tailwindcss 0.0.0-insiders.bd4dddd → 0.0.0-insiders.bda8421
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/LICENSE +1 -2
- package/README.md +13 -10
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- package/lib/cli/build/deps.js +62 -0
- package/lib/cli/build/index.js +54 -0
- package/lib/cli/build/plugin.js +371 -0
- package/lib/cli/build/utils.js +88 -0
- package/lib/cli/build/watching.js +182 -0
- package/lib/cli/help/index.js +73 -0
- package/lib/cli/index.js +230 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli-peer-dependencies.js +28 -7
- package/lib/cli.js +1 -741
- package/lib/corePluginList.js +17 -4
- package/lib/corePlugins.js +2503 -1839
- package/lib/css/preflight.css +32 -13
- package/lib/featureFlags.js +45 -28
- package/lib/index.js +1 -29
- package/lib/lib/cacheInvalidation.js +92 -0
- package/lib/lib/collapseAdjacentRules.js +30 -10
- package/lib/lib/collapseDuplicateDeclarations.js +13 -8
- package/lib/lib/content.js +214 -0
- package/lib/lib/defaultExtractor.js +240 -31
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +466 -230
- package/lib/lib/expandTailwindAtRules.js +156 -135
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +554 -200
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/load-config.js +57 -0
- package/lib/lib/normalizeTailwindDirectives.js +39 -33
- package/lib/lib/offsets.js +355 -0
- package/lib/lib/partitionApplyAtRules.js +58 -0
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +97 -69
- package/lib/lib/setupContextUtils.js +796 -341
- package/lib/lib/setupTrackingContext.js +66 -71
- package/lib/lib/sharedState.js +45 -14
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/plugin.js +48 -0
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +21 -0
- package/lib/postcss-plugins/nesting/plugin.js +89 -0
- package/lib/processTailwindFeatures.js +37 -27
- package/lib/public/colors.js +272 -246
- package/lib/public/create-plugin.js +9 -5
- package/lib/public/default-config.js +10 -6
- package/lib/public/default-theme.js +10 -6
- package/lib/public/load-config.js +12 -0
- package/lib/public/resolve-config.js +11 -6
- package/lib/util/applyImportantSelector.js +36 -0
- package/lib/util/bigSign.js +6 -1
- package/lib/util/buildMediaQuery.js +13 -6
- package/lib/util/cloneDeep.js +9 -6
- package/lib/util/cloneNodes.js +44 -4
- package/lib/util/color.js +70 -53
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -6
- package/lib/util/createUtilityPlugin.js +16 -16
- package/lib/util/dataTypes.js +295 -113
- package/lib/util/defaults.js +12 -7
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -12
- package/lib/util/formatVariantSelector.js +235 -151
- package/lib/util/getAllConfigs.js +33 -12
- package/lib/util/hashConfig.js +9 -4
- package/lib/util/isKeyframeRule.js +7 -2
- package/lib/util/isPlainObject.js +8 -3
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
- package/lib/util/log.js +25 -15
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +127 -82
- package/lib/util/normalizeScreens.js +128 -11
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +34 -23
- package/lib/util/parseDependency.js +39 -55
- package/lib/util/parseGlob.js +36 -0
- package/lib/util/parseObjectStyles.js +15 -10
- package/lib/util/pluginUtils.js +172 -69
- package/lib/util/prefixSelector.js +30 -12
- package/lib/util/pseudoElements.js +212 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +101 -87
- package/lib/util/resolveConfigPath.js +30 -12
- package/lib/util/responsive.js +11 -6
- package/lib/util/splitAtTopLevelOnly.js +51 -0
- package/lib/util/tap.js +6 -1
- package/lib/util/toColorValue.js +7 -3
- package/lib/util/toPath.js +22 -4
- package/lib/util/transformThemeValue.js +40 -30
- package/lib/util/validateConfig.js +37 -0
- package/lib/util/validateFormalSyntax.js +26 -0
- package/lib/util/withAlphaVariable.js +27 -15
- package/lib/value-parser/LICENSE +22 -0
- package/lib/value-parser/README.md +3 -0
- package/lib/value-parser/index.d.js +2 -0
- package/lib/value-parser/index.js +22 -0
- package/lib/value-parser/parse.js +259 -0
- package/lib/value-parser/stringify.js +38 -0
- package/lib/value-parser/unit.js +86 -0
- package/lib/value-parser/walk.js +16 -0
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/nesting/index.d.ts +4 -0
- package/nesting/index.js +2 -12
- package/package.json +60 -55
- package/peers/index.js +75503 -55095
- package/plugin.d.ts +11 -0
- package/resolveConfig.d.ts +31 -0
- package/scripts/generate-types.js +104 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/deps.js +56 -0
- package/src/cli/build/index.js +49 -0
- package/src/cli/build/plugin.js +437 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +229 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +216 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +1 -811
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +849 -243
- package/src/css/preflight.css +32 -13
- package/src/featureFlags.js +13 -9
- package/src/index.js +1 -28
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/content.js +249 -0
- package/src/lib/defaultExtractor.js +215 -33
- package/src/lib/evaluateTailwindFunctions.js +82 -8
- package/src/lib/expandApplyAtRules.js +512 -224
- package/src/lib/expandTailwindAtRules.js +102 -87
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +541 -146
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/load-config.ts +44 -0
- package/src/lib/normalizeTailwindDirectives.js +1 -0
- package/src/lib/offsets.js +432 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +55 -30
- package/src/lib/setupContextUtils.js +720 -190
- package/src/lib/setupTrackingContext.js +47 -61
- package/src/lib/sharedState.js +15 -4
- package/src/plugin.js +47 -0
- 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 +11 -4
- package/src/public/colors.js +22 -0
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/applyImportantSelector.js +27 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +40 -2
- package/src/util/color.js +39 -20
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +184 -26
- package/src/util/formatVariantSelector.js +272 -144
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/isPlainObject.js +1 -1
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +8 -8
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +45 -6
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +4 -3
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +139 -24
- package/src/util/prefixSelector.js +31 -10
- package/src/util/pseudoElements.js +171 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -32
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +26 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/src/value-parser/LICENSE +22 -0
- package/src/value-parser/README.md +3 -0
- package/src/value-parser/index.d.ts +177 -0
- package/src/value-parser/index.js +28 -0
- package/src/value-parser/parse.js +303 -0
- package/src/value-parser/stringify.js +41 -0
- package/src/value-parser/unit.js +118 -0
- package/src/value-parser/walk.js +18 -0
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +290 -178
- package/stubs/postcss.config.js +6 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/types/config.d.ts +376 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +298 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +397 -0
- package/types/index.d.ts +11 -0
- package/CHANGELOG.md +0 -1959
- package/lib/constants.js +0 -37
- package/lib/lib/detectNesting.js +0 -34
- package/nesting/plugin.js +0 -41
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/constants.js +0 -17
- package/src/lib/detectNesting.js +0 -39
- /package/stubs/{simpleConfig.stub.js → config.simple.js} +0 -0
- /package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -0
|
@@ -2,82 +2,168 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
function
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
INTERNAL_FEATURES: function() {
|
|
13
|
+
return INTERNAL_FEATURES;
|
|
14
|
+
},
|
|
15
|
+
isValidVariantFormatString: function() {
|
|
16
|
+
return isValidVariantFormatString;
|
|
17
|
+
},
|
|
18
|
+
parseVariant: function() {
|
|
19
|
+
return parseVariant;
|
|
20
|
+
},
|
|
21
|
+
getFileModifiedMap: function() {
|
|
22
|
+
return getFileModifiedMap;
|
|
23
|
+
},
|
|
24
|
+
createContext: function() {
|
|
25
|
+
return createContext;
|
|
26
|
+
},
|
|
27
|
+
getContext: function() {
|
|
28
|
+
return getContext;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
32
|
+
const _url = /*#__PURE__*/ _interop_require_default(require("url"));
|
|
33
|
+
const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
|
|
34
|
+
const _dlv = /*#__PURE__*/ _interop_require_default(require("dlv"));
|
|
35
|
+
const _postcssselectorparser = /*#__PURE__*/ _interop_require_default(require("postcss-selector-parser"));
|
|
36
|
+
const _transformThemeValue = /*#__PURE__*/ _interop_require_default(require("../util/transformThemeValue"));
|
|
37
|
+
const _parseObjectStyles = /*#__PURE__*/ _interop_require_default(require("../util/parseObjectStyles"));
|
|
38
|
+
const _prefixSelector = /*#__PURE__*/ _interop_require_default(require("../util/prefixSelector"));
|
|
39
|
+
const _isPlainObject = /*#__PURE__*/ _interop_require_default(require("../util/isPlainObject"));
|
|
40
|
+
const _escapeClassName = /*#__PURE__*/ _interop_require_default(require("../util/escapeClassName"));
|
|
41
|
+
const _nameClass = /*#__PURE__*/ _interop_require_wildcard(require("../util/nameClass"));
|
|
42
|
+
const _pluginUtils = require("../util/pluginUtils");
|
|
43
|
+
const _corePlugins = require("../corePlugins");
|
|
44
|
+
const _sharedState = /*#__PURE__*/ _interop_require_wildcard(require("./sharedState"));
|
|
45
|
+
const _toPath = require("../util/toPath");
|
|
46
|
+
const _log = /*#__PURE__*/ _interop_require_default(require("../util/log"));
|
|
47
|
+
const _negateValue = /*#__PURE__*/ _interop_require_default(require("../util/negateValue"));
|
|
48
|
+
const _isSyntacticallyValidPropertyValue = /*#__PURE__*/ _interop_require_default(require("../util/isSyntacticallyValidPropertyValue"));
|
|
49
|
+
const _generateRules = require("./generateRules");
|
|
50
|
+
const _cacheInvalidation = require("./cacheInvalidation.js");
|
|
51
|
+
const _offsets = require("./offsets.js");
|
|
52
|
+
const _featureFlags = require("../featureFlags.js");
|
|
53
|
+
const _formatVariantSelector = require("../util/formatVariantSelector");
|
|
54
|
+
function _interop_require_default(obj) {
|
|
28
55
|
return obj && obj.__esModule ? obj : {
|
|
29
56
|
default: obj
|
|
30
57
|
};
|
|
31
58
|
}
|
|
32
|
-
function
|
|
33
|
-
if (
|
|
59
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
60
|
+
if (typeof WeakMap !== "function") return null;
|
|
61
|
+
var cacheBabelInterop = new WeakMap();
|
|
62
|
+
var cacheNodeInterop = new WeakMap();
|
|
63
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
64
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
65
|
+
})(nodeInterop);
|
|
66
|
+
}
|
|
67
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
68
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
34
69
|
return obj;
|
|
35
|
-
}
|
|
36
|
-
|
|
70
|
+
}
|
|
71
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
72
|
+
return {
|
|
73
|
+
default: obj
|
|
37
74
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
75
|
+
}
|
|
76
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
77
|
+
if (cache && cache.has(obj)) {
|
|
78
|
+
return cache.get(obj);
|
|
79
|
+
}
|
|
80
|
+
var newObj = {};
|
|
81
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
82
|
+
for(var key in obj){
|
|
83
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
84
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
85
|
+
if (desc && (desc.get || desc.set)) {
|
|
86
|
+
Object.defineProperty(newObj, key, desc);
|
|
87
|
+
} else {
|
|
88
|
+
newObj[key] = obj[key];
|
|
49
89
|
}
|
|
50
90
|
}
|
|
51
|
-
newObj.default = obj;
|
|
52
|
-
return newObj;
|
|
53
91
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!isBalanced(input)) throw new Error(`Your { and } are unbalanced.`);
|
|
58
|
-
return input.split(/{(.*)}/gim).flatMap((line)=>parseVariantFormatString(line)
|
|
59
|
-
).filter(Boolean);
|
|
92
|
+
newObj.default = obj;
|
|
93
|
+
if (cache) {
|
|
94
|
+
cache.set(obj, newObj);
|
|
60
95
|
}
|
|
61
|
-
return
|
|
62
|
-
|
|
63
|
-
|
|
96
|
+
return newObj;
|
|
97
|
+
}
|
|
98
|
+
const INTERNAL_FEATURES = Symbol();
|
|
99
|
+
const VARIANT_TYPES = {
|
|
100
|
+
AddVariant: Symbol.for("ADD_VARIANT"),
|
|
101
|
+
MatchVariant: Symbol.for("MATCH_VARIANT")
|
|
102
|
+
};
|
|
103
|
+
const VARIANT_INFO = {
|
|
104
|
+
Base: 1 << 0,
|
|
105
|
+
Dynamic: 1 << 1
|
|
106
|
+
};
|
|
107
|
+
function prefix(context, selector) {
|
|
108
|
+
let prefix = context.tailwindConfig.prefix;
|
|
109
|
+
return typeof prefix === "function" ? prefix(selector) : prefix + selector;
|
|
110
|
+
}
|
|
111
|
+
function normalizeOptionTypes({ type ="any" , ...options }) {
|
|
112
|
+
let types = [].concat(type);
|
|
113
|
+
return {
|
|
114
|
+
...options,
|
|
115
|
+
types: types.map((type)=>{
|
|
116
|
+
if (Array.isArray(type)) {
|
|
117
|
+
return {
|
|
118
|
+
type: type[0],
|
|
119
|
+
...type[1]
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
type,
|
|
124
|
+
preferOnConflict: false
|
|
125
|
+
};
|
|
126
|
+
})
|
|
127
|
+
};
|
|
64
128
|
}
|
|
65
|
-
function
|
|
66
|
-
let
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
129
|
+
function parseVariantFormatString(input) {
|
|
130
|
+
/** @type {string[]} */ let parts = [];
|
|
131
|
+
// When parsing whitespace around special characters are insignificant
|
|
132
|
+
// However, _inside_ of a variant they could be
|
|
133
|
+
// Because the selector could look like this
|
|
134
|
+
// @media { &[data-name="foo bar"] }
|
|
135
|
+
// This is why we do not skip whitespace
|
|
136
|
+
let current = "";
|
|
137
|
+
let depth = 0;
|
|
138
|
+
for(let idx = 0; idx < input.length; idx++){
|
|
139
|
+
let char = input[idx];
|
|
140
|
+
if (char === "\\") {
|
|
141
|
+
// Escaped characters are not special
|
|
142
|
+
current += "\\" + input[++idx];
|
|
143
|
+
} else if (char === "{") {
|
|
144
|
+
// Nested rule: start
|
|
145
|
+
++depth;
|
|
146
|
+
parts.push(current.trim());
|
|
147
|
+
current = "";
|
|
148
|
+
} else if (char === "}") {
|
|
149
|
+
// Nested rule: end
|
|
150
|
+
if (--depth < 0) {
|
|
151
|
+
throw new Error(`Your { and } are unbalanced.`);
|
|
74
152
|
}
|
|
153
|
+
parts.push(current.trim());
|
|
154
|
+
current = "";
|
|
155
|
+
} else {
|
|
156
|
+
// Normal character
|
|
157
|
+
current += char;
|
|
75
158
|
}
|
|
76
159
|
}
|
|
77
|
-
|
|
160
|
+
if (current.length > 0) {
|
|
161
|
+
parts.push(current.trim());
|
|
162
|
+
}
|
|
163
|
+
parts = parts.filter((part)=>part !== "");
|
|
164
|
+
return parts;
|
|
78
165
|
}
|
|
79
|
-
function insertInto(list, value, { before =[] } = {
|
|
80
|
-
}) {
|
|
166
|
+
function insertInto(list, value, { before =[] } = {}) {
|
|
81
167
|
before = [].concat(before);
|
|
82
168
|
if (before.length <= 0) {
|
|
83
169
|
list.push(value);
|
|
@@ -98,13 +184,16 @@ function parseStyles(styles) {
|
|
|
98
184
|
]);
|
|
99
185
|
}
|
|
100
186
|
return styles.flatMap((style)=>{
|
|
101
|
-
let isNode = !Array.isArray(style) && !(0, _isPlainObject
|
|
102
|
-
return isNode ? style : (0, _parseObjectStyles
|
|
187
|
+
let isNode = !Array.isArray(style) && !(0, _isPlainObject.default)(style);
|
|
188
|
+
return isNode ? style : (0, _parseObjectStyles.default)(style);
|
|
103
189
|
});
|
|
104
190
|
}
|
|
105
|
-
function getClasses(selector) {
|
|
106
|
-
let parser = (0,
|
|
191
|
+
function getClasses(selector, mutate) {
|
|
192
|
+
let parser = (0, _postcssselectorparser.default)((selectors)=>{
|
|
107
193
|
let allClasses = [];
|
|
194
|
+
if (mutate) {
|
|
195
|
+
mutate(selectors);
|
|
196
|
+
}
|
|
108
197
|
selectors.walkClasses((classNode)=>{
|
|
109
198
|
allClasses.push(classNode.value);
|
|
110
199
|
});
|
|
@@ -112,44 +201,61 @@ function getClasses(selector) {
|
|
|
112
201
|
});
|
|
113
202
|
return parser.transformSync(selector);
|
|
114
203
|
}
|
|
115
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Ignore everything inside a :not(...). This allows you to write code like
|
|
206
|
+
* `div:not(.foo)`. If `.foo` is never found in your code, then we used to
|
|
207
|
+
* not generated it. But now we will ignore everything inside a `:not`, so
|
|
208
|
+
* that it still gets generated.
|
|
209
|
+
*
|
|
210
|
+
* @param {selectorParser.Root} selectors
|
|
211
|
+
*/ function ignoreNot(selectors) {
|
|
212
|
+
selectors.walkPseudos((pseudo)=>{
|
|
213
|
+
if (pseudo.value === ":not") {
|
|
214
|
+
pseudo.remove();
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
function extractCandidates(node, state = {
|
|
219
|
+
containsNonOnDemandable: false
|
|
220
|
+
}, depth = 0) {
|
|
116
221
|
let classes = [];
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
222
|
+
let selectors = [];
|
|
223
|
+
if (node.type === "rule") {
|
|
224
|
+
// Handle normal rules
|
|
225
|
+
selectors.push(...node.selectors);
|
|
226
|
+
} else if (node.type === "atrule") {
|
|
227
|
+
// Handle at-rules (which contains nested rules)
|
|
228
|
+
node.walkRules((rule)=>selectors.push(...rule.selectors));
|
|
229
|
+
}
|
|
230
|
+
for (let selector of selectors){
|
|
231
|
+
let classCandidates = getClasses(selector, ignoreNot);
|
|
232
|
+
// At least one of the selectors contains non-"on-demandable" candidates.
|
|
233
|
+
if (classCandidates.length === 0) {
|
|
234
|
+
state.containsNonOnDemandable = true;
|
|
235
|
+
}
|
|
236
|
+
for (let classCandidate of classCandidates){
|
|
237
|
+
classes.push(classCandidate);
|
|
126
238
|
}
|
|
127
|
-
return classes;
|
|
128
239
|
}
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
classes
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
)
|
|
135
|
-
];
|
|
136
|
-
});
|
|
240
|
+
if (depth === 0) {
|
|
241
|
+
return [
|
|
242
|
+
state.containsNonOnDemandable || classes.length === 0,
|
|
243
|
+
classes
|
|
244
|
+
];
|
|
137
245
|
}
|
|
138
246
|
return classes;
|
|
139
247
|
}
|
|
140
248
|
function withIdentifiers(styles) {
|
|
141
249
|
return parseStyles(styles).flatMap((node)=>{
|
|
142
250
|
let nodeMap = new Map();
|
|
143
|
-
let candidates = extractCandidates(node);
|
|
144
|
-
// If this isn't "on-demandable", assign it a universal candidate.
|
|
145
|
-
if (
|
|
146
|
-
|
|
147
|
-
[
|
|
148
|
-
'*',
|
|
149
|
-
node
|
|
150
|
-
]
|
|
151
|
-
];
|
|
251
|
+
let [containsNonOnDemandableSelectors, candidates] = extractCandidates(node);
|
|
252
|
+
// If this isn't "on-demandable", assign it a universal candidate to always include it.
|
|
253
|
+
if (containsNonOnDemandableSelectors) {
|
|
254
|
+
candidates.unshift(_sharedState.NOT_ON_DEMAND);
|
|
152
255
|
}
|
|
256
|
+
// However, it could be that it also contains "on-demandable" candidates.
|
|
257
|
+
// E.g.: `span, .foo {}`, in that case it should still be possible to use
|
|
258
|
+
// `@apply foo` for example.
|
|
153
259
|
return candidates.map((c)=>{
|
|
154
260
|
if (!nodeMap.has(node)) {
|
|
155
261
|
nodeMap.set(node, node);
|
|
@@ -161,77 +267,73 @@ function withIdentifiers(styles) {
|
|
|
161
267
|
});
|
|
162
268
|
});
|
|
163
269
|
}
|
|
164
|
-
function
|
|
270
|
+
function isValidVariantFormatString(format) {
|
|
271
|
+
return format.startsWith("@") || format.includes("&");
|
|
272
|
+
}
|
|
273
|
+
function parseVariant(variant) {
|
|
274
|
+
variant = variant.replace(/\n+/g, "").replace(/\s{1,}/g, " ").trim();
|
|
275
|
+
let fns = parseVariantFormatString(variant).map((str)=>{
|
|
276
|
+
if (!str.startsWith("@")) {
|
|
277
|
+
return ({ format })=>format(str);
|
|
278
|
+
}
|
|
279
|
+
let [, name, params] = /@(\S*)( .+|[({].*)?/g.exec(str);
|
|
280
|
+
var _params_trim;
|
|
281
|
+
return ({ wrap })=>{
|
|
282
|
+
return wrap(_postcss.default.atRule({
|
|
283
|
+
name,
|
|
284
|
+
params: (_params_trim = params === null || params === void 0 ? void 0 : params.trim()) !== null && _params_trim !== void 0 ? _params_trim : ""
|
|
285
|
+
}));
|
|
286
|
+
};
|
|
287
|
+
}).reverse();
|
|
288
|
+
return (api)=>{
|
|
289
|
+
for (let fn of fns){
|
|
290
|
+
fn(api);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
*
|
|
296
|
+
* @param {any} tailwindConfig
|
|
297
|
+
* @param {any} context
|
|
298
|
+
* @param {object} param2
|
|
299
|
+
* @param {Offsets} param2.offsets
|
|
300
|
+
*/ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , offsets , classList }) {
|
|
165
301
|
function getConfigValue(path, defaultValue) {
|
|
166
|
-
return path ? (0, _dlv
|
|
302
|
+
return path ? (0, _dlv.default)(tailwindConfig, path, defaultValue) : tailwindConfig;
|
|
167
303
|
}
|
|
168
304
|
function applyConfiguredPrefix(selector) {
|
|
169
|
-
return (0, _prefixSelector
|
|
305
|
+
return (0, _prefixSelector.default)(tailwindConfig.prefix, selector);
|
|
170
306
|
}
|
|
171
307
|
function prefixIdentifier(identifier, options) {
|
|
172
|
-
if (identifier ===
|
|
173
|
-
return
|
|
308
|
+
if (identifier === _sharedState.NOT_ON_DEMAND) {
|
|
309
|
+
return _sharedState.NOT_ON_DEMAND;
|
|
174
310
|
}
|
|
175
311
|
if (!options.respectPrefix) {
|
|
176
312
|
return identifier;
|
|
177
313
|
}
|
|
178
314
|
return context.tailwindConfig.prefix + identifier;
|
|
179
315
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
separator
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
variantFunction = variantFunction.replace(/\n+/g, '').replace(/\s{1,}/g, ' ').trim();
|
|
195
|
-
let fns = parseVariantFormatString(variantFunction).map((str)=>{
|
|
196
|
-
if (!str.startsWith('@')) {
|
|
197
|
-
return ({ format })=>format(str)
|
|
198
|
-
;
|
|
199
|
-
}
|
|
200
|
-
let [, name, params] = /@(.*?) (.*)/g.exec(str);
|
|
201
|
-
return ({ wrap })=>wrap(_postcss.default.atRule({
|
|
202
|
-
name,
|
|
203
|
-
params
|
|
204
|
-
}))
|
|
205
|
-
;
|
|
206
|
-
}).reverse();
|
|
207
|
-
return (api)=>{
|
|
208
|
-
for (let fn of fns){
|
|
209
|
-
fn(api);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
});
|
|
213
|
-
insertInto(variantList, variantName, options);
|
|
214
|
-
variantMap.set(variantName, variantFunctions);
|
|
215
|
-
},
|
|
316
|
+
function resolveThemeValue(path, defaultValue, opts = {}) {
|
|
317
|
+
let parts = (0, _toPath.toPath)(path);
|
|
318
|
+
let value = getConfigValue([
|
|
319
|
+
"theme",
|
|
320
|
+
...parts
|
|
321
|
+
], defaultValue);
|
|
322
|
+
return (0, _transformThemeValue.default)(parts[0])(value, opts);
|
|
323
|
+
}
|
|
324
|
+
let variantIdentifier = 0;
|
|
325
|
+
let api = {
|
|
216
326
|
postcss: _postcss.default,
|
|
217
327
|
prefix: applyConfiguredPrefix,
|
|
218
328
|
e: _escapeClassName.default,
|
|
219
329
|
config: getConfigValue,
|
|
220
|
-
theme
|
|
221
|
-
const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
|
|
222
|
-
const value = getConfigValue([
|
|
223
|
-
'theme',
|
|
224
|
-
pathRoot,
|
|
225
|
-
...subPaths
|
|
226
|
-
], defaultValue);
|
|
227
|
-
return (0, _transformThemeValue).default(pathRoot)(value);
|
|
228
|
-
},
|
|
330
|
+
theme: resolveThemeValue,
|
|
229
331
|
corePlugins: (path)=>{
|
|
230
332
|
if (Array.isArray(tailwindConfig.corePlugins)) {
|
|
231
333
|
return tailwindConfig.corePlugins.includes(path);
|
|
232
334
|
}
|
|
233
335
|
return getConfigValue([
|
|
234
|
-
|
|
336
|
+
"corePlugins",
|
|
235
337
|
path
|
|
236
338
|
], true);
|
|
237
339
|
},
|
|
@@ -239,33 +341,17 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
239
341
|
// Preserved for backwards compatibility but not used in v3.0+
|
|
240
342
|
return [];
|
|
241
343
|
},
|
|
242
|
-
addUserCss (userCss) {
|
|
243
|
-
for (let [identifier, rule] of withIdentifiers(userCss)){
|
|
244
|
-
let offset = offsets.user++;
|
|
245
|
-
if (!context.candidateRuleMap.has(identifier)) {
|
|
246
|
-
context.candidateRuleMap.set(identifier, []);
|
|
247
|
-
}
|
|
248
|
-
context.candidateRuleMap.get(identifier).push([
|
|
249
|
-
{
|
|
250
|
-
sort: offset,
|
|
251
|
-
layer: 'user'
|
|
252
|
-
},
|
|
253
|
-
rule
|
|
254
|
-
]);
|
|
255
|
-
}
|
|
256
|
-
},
|
|
257
344
|
addBase (base) {
|
|
258
345
|
for (let [identifier, rule] of withIdentifiers(base)){
|
|
259
|
-
let prefixedIdentifier = prefixIdentifier(identifier, {
|
|
260
|
-
|
|
261
|
-
let offset = offsets.base++;
|
|
346
|
+
let prefixedIdentifier = prefixIdentifier(identifier, {});
|
|
347
|
+
let offset = offsets.create("base");
|
|
262
348
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
263
349
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
264
350
|
}
|
|
265
351
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
266
352
|
{
|
|
267
353
|
sort: offset,
|
|
268
|
-
layer:
|
|
354
|
+
layer: "base"
|
|
269
355
|
},
|
|
270
356
|
rule
|
|
271
357
|
]);
|
|
@@ -279,16 +365,14 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
279
365
|
[`@defaults ${group}`]: declarations
|
|
280
366
|
};
|
|
281
367
|
for (let [identifier, rule] of withIdentifiers(groups)){
|
|
282
|
-
let prefixedIdentifier = prefixIdentifier(identifier, {
|
|
283
|
-
});
|
|
284
|
-
let offset = offsets.base++;
|
|
368
|
+
let prefixedIdentifier = prefixIdentifier(identifier, {});
|
|
285
369
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
286
370
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
287
371
|
}
|
|
288
372
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
289
373
|
{
|
|
290
|
-
sort:
|
|
291
|
-
layer:
|
|
374
|
+
sort: offsets.create("defaults"),
|
|
375
|
+
layer: "defaults"
|
|
292
376
|
},
|
|
293
377
|
rule
|
|
294
378
|
]);
|
|
@@ -296,23 +380,21 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
296
380
|
},
|
|
297
381
|
addComponents (components, options) {
|
|
298
382
|
let defaultOptions = {
|
|
383
|
+
preserveSource: false,
|
|
299
384
|
respectPrefix: true,
|
|
300
385
|
respectImportant: false
|
|
301
386
|
};
|
|
302
|
-
options = Object.assign({
|
|
303
|
-
}, defaultOptions, Array.isArray(options) ? {
|
|
304
|
-
} : options);
|
|
387
|
+
options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options);
|
|
305
388
|
for (let [identifier, rule] of withIdentifiers(components)){
|
|
306
389
|
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
307
|
-
let offset = offsets.components++;
|
|
308
390
|
classList.add(prefixedIdentifier);
|
|
309
391
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
310
392
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
311
393
|
}
|
|
312
394
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
313
395
|
{
|
|
314
|
-
sort:
|
|
315
|
-
layer:
|
|
396
|
+
sort: offsets.create("components"),
|
|
397
|
+
layer: "components",
|
|
316
398
|
options
|
|
317
399
|
},
|
|
318
400
|
rule
|
|
@@ -321,23 +403,21 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
321
403
|
},
|
|
322
404
|
addUtilities (utilities, options) {
|
|
323
405
|
let defaultOptions = {
|
|
406
|
+
preserveSource: false,
|
|
324
407
|
respectPrefix: true,
|
|
325
408
|
respectImportant: true
|
|
326
409
|
};
|
|
327
|
-
options = Object.assign({
|
|
328
|
-
}, defaultOptions, Array.isArray(options) ? {
|
|
329
|
-
} : options);
|
|
410
|
+
options = Object.assign({}, defaultOptions, Array.isArray(options) ? {} : options);
|
|
330
411
|
for (let [identifier, rule] of withIdentifiers(utilities)){
|
|
331
412
|
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
332
|
-
let offset = offsets.utilities++;
|
|
333
413
|
classList.add(prefixedIdentifier);
|
|
334
414
|
if (!context.candidateRuleMap.has(prefixedIdentifier)) {
|
|
335
415
|
context.candidateRuleMap.set(prefixedIdentifier, []);
|
|
336
416
|
}
|
|
337
417
|
context.candidateRuleMap.get(prefixedIdentifier).push([
|
|
338
418
|
{
|
|
339
|
-
sort:
|
|
340
|
-
layer:
|
|
419
|
+
sort: offsets.create("utilities"),
|
|
420
|
+
layer: "utilities",
|
|
341
421
|
options
|
|
342
422
|
},
|
|
343
423
|
rule
|
|
@@ -347,13 +427,14 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
347
427
|
matchUtilities: function(utilities, options) {
|
|
348
428
|
let defaultOptions = {
|
|
349
429
|
respectPrefix: true,
|
|
350
|
-
respectImportant: true
|
|
430
|
+
respectImportant: true,
|
|
431
|
+
modifiers: false
|
|
351
432
|
};
|
|
352
|
-
options = {
|
|
433
|
+
options = normalizeOptionTypes({
|
|
353
434
|
...defaultOptions,
|
|
354
435
|
...options
|
|
355
|
-
};
|
|
356
|
-
let offset = offsets.utilities
|
|
436
|
+
});
|
|
437
|
+
let offset = offsets.create("utilities");
|
|
357
438
|
for(let identifier in utilities){
|
|
358
439
|
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
359
440
|
let rule = utilities[identifier];
|
|
@@ -362,28 +443,43 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
362
443
|
options
|
|
363
444
|
]);
|
|
364
445
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
365
|
-
let
|
|
366
|
-
type = [].concat(type);
|
|
367
|
-
let [value, coercedType] = (0, _pluginUtils).coerceValue(type, modifier, options, tailwindConfig);
|
|
446
|
+
let [value, coercedType, utilityModifier] = (0, _pluginUtils.coerceValue)(options.types, modifier, options, tailwindConfig);
|
|
368
447
|
if (value === undefined) {
|
|
369
448
|
return [];
|
|
370
449
|
}
|
|
371
|
-
if (!
|
|
372
|
-
|
|
450
|
+
if (!options.types.some(({ type })=>type === coercedType)) {
|
|
451
|
+
if (isOnlyPlugin) {
|
|
452
|
+
_log.default.warn([
|
|
453
|
+
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
454
|
+
`You can safely update it to \`${identifier}-${modifier.replace(coercedType + ":", "")}\`.`
|
|
455
|
+
]);
|
|
456
|
+
} else {
|
|
457
|
+
return [];
|
|
458
|
+
}
|
|
373
459
|
}
|
|
374
|
-
if (!(0,
|
|
460
|
+
if (!(0, _isSyntacticallyValidPropertyValue.default)(value)) {
|
|
375
461
|
return [];
|
|
376
462
|
}
|
|
377
|
-
let
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
463
|
+
let extras = {
|
|
464
|
+
get modifier () {
|
|
465
|
+
if (!options.modifiers) {
|
|
466
|
+
_log.default.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
467
|
+
"Your plugin must set `modifiers: true` in its options to support modifiers."
|
|
468
|
+
]);
|
|
469
|
+
}
|
|
470
|
+
return utilityModifier;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
let modifiersEnabled = (0, _featureFlags.flagEnabled)(tailwindConfig, "generalizedModifiers");
|
|
474
|
+
let ruleSets = [].concat(modifiersEnabled ? rule(value, extras) : rule(value)).filter(Boolean).map((declaration)=>({
|
|
475
|
+
[(0, _nameClass.default)(identifier, modifier)]: declaration
|
|
476
|
+
}));
|
|
381
477
|
return ruleSets;
|
|
382
478
|
}
|
|
383
479
|
let withOffsets = [
|
|
384
480
|
{
|
|
385
481
|
sort: offset,
|
|
386
|
-
layer:
|
|
482
|
+
layer: "utilities",
|
|
387
483
|
options
|
|
388
484
|
},
|
|
389
485
|
wrapped
|
|
@@ -397,13 +493,14 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
397
493
|
matchComponents: function(components, options) {
|
|
398
494
|
let defaultOptions = {
|
|
399
495
|
respectPrefix: true,
|
|
400
|
-
respectImportant: false
|
|
496
|
+
respectImportant: false,
|
|
497
|
+
modifiers: false
|
|
401
498
|
};
|
|
402
|
-
options = {
|
|
499
|
+
options = normalizeOptionTypes({
|
|
403
500
|
...defaultOptions,
|
|
404
501
|
...options
|
|
405
|
-
};
|
|
406
|
-
let offset = offsets.components
|
|
502
|
+
});
|
|
503
|
+
let offset = offsets.create("components");
|
|
407
504
|
for(let identifier in components){
|
|
408
505
|
let prefixedIdentifier = prefixIdentifier(identifier, options);
|
|
409
506
|
let rule = components[identifier];
|
|
@@ -412,35 +509,43 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
412
509
|
options
|
|
413
510
|
]);
|
|
414
511
|
function wrapped(modifier, { isOnlyPlugin }) {
|
|
415
|
-
let
|
|
416
|
-
type = [].concat(type);
|
|
417
|
-
let [value, coercedType] = (0, _pluginUtils).coerceValue(type, modifier, options, tailwindConfig);
|
|
512
|
+
let [value, coercedType, utilityModifier] = (0, _pluginUtils.coerceValue)(options.types, modifier, options, tailwindConfig);
|
|
418
513
|
if (value === undefined) {
|
|
419
514
|
return [];
|
|
420
515
|
}
|
|
421
|
-
if (!
|
|
516
|
+
if (!options.types.some(({ type })=>type === coercedType)) {
|
|
422
517
|
if (isOnlyPlugin) {
|
|
423
518
|
_log.default.warn([
|
|
424
519
|
`Unnecessary typehint \`${coercedType}\` in \`${identifier}-${modifier}\`.`,
|
|
425
|
-
`You can safely update it to \`${identifier}-${modifier.replace(coercedType +
|
|
520
|
+
`You can safely update it to \`${identifier}-${modifier.replace(coercedType + ":", "")}\`.`
|
|
426
521
|
]);
|
|
427
522
|
} else {
|
|
428
523
|
return [];
|
|
429
524
|
}
|
|
430
525
|
}
|
|
431
|
-
if (!(0,
|
|
526
|
+
if (!(0, _isSyntacticallyValidPropertyValue.default)(value)) {
|
|
432
527
|
return [];
|
|
433
528
|
}
|
|
434
|
-
let
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
529
|
+
let extras = {
|
|
530
|
+
get modifier () {
|
|
531
|
+
if (!options.modifiers) {
|
|
532
|
+
_log.default.warn(`modifier-used-without-options-for-${identifier}`, [
|
|
533
|
+
"Your plugin must set `modifiers: true` in its options to support modifiers."
|
|
534
|
+
]);
|
|
535
|
+
}
|
|
536
|
+
return utilityModifier;
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
let modifiersEnabled = (0, _featureFlags.flagEnabled)(tailwindConfig, "generalizedModifiers");
|
|
540
|
+
let ruleSets = [].concat(modifiersEnabled ? rule(value, extras) : rule(value)).filter(Boolean).map((declaration)=>({
|
|
541
|
+
[(0, _nameClass.default)(identifier, modifier)]: declaration
|
|
542
|
+
}));
|
|
438
543
|
return ruleSets;
|
|
439
544
|
}
|
|
440
545
|
let withOffsets = [
|
|
441
546
|
{
|
|
442
547
|
sort: offset,
|
|
443
|
-
layer:
|
|
548
|
+
layer: "components",
|
|
444
549
|
options
|
|
445
550
|
},
|
|
446
551
|
wrapped
|
|
@@ -450,8 +555,90 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
450
555
|
}
|
|
451
556
|
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets);
|
|
452
557
|
}
|
|
558
|
+
},
|
|
559
|
+
addVariant (variantName, variantFunctions, options = {}) {
|
|
560
|
+
variantFunctions = [].concat(variantFunctions).map((variantFunction)=>{
|
|
561
|
+
if (typeof variantFunction !== "string") {
|
|
562
|
+
// Safelist public API functions
|
|
563
|
+
return (api = {})=>{
|
|
564
|
+
let { args , modifySelectors , container , separator , wrap , format } = api;
|
|
565
|
+
let result = variantFunction(Object.assign({
|
|
566
|
+
modifySelectors,
|
|
567
|
+
container,
|
|
568
|
+
separator
|
|
569
|
+
}, options.type === VARIANT_TYPES.MatchVariant && {
|
|
570
|
+
args,
|
|
571
|
+
wrap,
|
|
572
|
+
format
|
|
573
|
+
}));
|
|
574
|
+
if (typeof result === "string" && !isValidVariantFormatString(result)) {
|
|
575
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
576
|
+
}
|
|
577
|
+
if (Array.isArray(result)) {
|
|
578
|
+
return result.filter((variant)=>typeof variant === "string").map((variant)=>parseVariant(variant));
|
|
579
|
+
}
|
|
580
|
+
// result may be undefined with legacy variants that use APIs like `modifySelectors`
|
|
581
|
+
// result may also be a postcss node if someone was returning the result from `modifySelectors`
|
|
582
|
+
return result && typeof result === "string" && parseVariant(result)(api);
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
586
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
587
|
+
}
|
|
588
|
+
return parseVariant(variantFunction);
|
|
589
|
+
});
|
|
590
|
+
insertInto(variantList, variantName, options);
|
|
591
|
+
variantMap.set(variantName, variantFunctions);
|
|
592
|
+
context.variantOptions.set(variantName, options);
|
|
593
|
+
},
|
|
594
|
+
matchVariant (variant, variantFn, options) {
|
|
595
|
+
var _options_id;
|
|
596
|
+
// A unique identifier that "groups" these variants together.
|
|
597
|
+
// This is for internal use only which is why it is not present in the types
|
|
598
|
+
let id = (_options_id = options === null || options === void 0 ? void 0 : options.id) !== null && _options_id !== void 0 ? _options_id : ++variantIdentifier;
|
|
599
|
+
let isSpecial = variant === "@";
|
|
600
|
+
let modifiersEnabled = (0, _featureFlags.flagEnabled)(tailwindConfig, "generalizedModifiers");
|
|
601
|
+
var _options_values;
|
|
602
|
+
for (let [key, value] of Object.entries((_options_values = options === null || options === void 0 ? void 0 : options.values) !== null && _options_values !== void 0 ? _options_values : {})){
|
|
603
|
+
if (key === "DEFAULT") continue;
|
|
604
|
+
api.addVariant(isSpecial ? `${variant}${key}` : `${variant}-${key}`, ({ args , container })=>{
|
|
605
|
+
return variantFn(value, modifiersEnabled ? {
|
|
606
|
+
modifier: args === null || args === void 0 ? void 0 : args.modifier,
|
|
607
|
+
container
|
|
608
|
+
} : {
|
|
609
|
+
container
|
|
610
|
+
});
|
|
611
|
+
}, {
|
|
612
|
+
...options,
|
|
613
|
+
value,
|
|
614
|
+
id,
|
|
615
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
616
|
+
variantInfo: VARIANT_INFO.Base
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
var _options_values1;
|
|
620
|
+
let hasDefault = "DEFAULT" in ((_options_values1 = options === null || options === void 0 ? void 0 : options.values) !== null && _options_values1 !== void 0 ? _options_values1 : {});
|
|
621
|
+
api.addVariant(variant, ({ args , container })=>{
|
|
622
|
+
if ((args === null || args === void 0 ? void 0 : args.value) === _sharedState.NONE && !hasDefault) {
|
|
623
|
+
return null;
|
|
624
|
+
}
|
|
625
|
+
var // (JetBrains) plugins.
|
|
626
|
+
_args_value;
|
|
627
|
+
return variantFn((args === null || args === void 0 ? void 0 : args.value) === _sharedState.NONE ? options.values.DEFAULT : (_args_value = args === null || args === void 0 ? void 0 : args.value) !== null && _args_value !== void 0 ? _args_value : typeof args === "string" ? args : "", modifiersEnabled ? {
|
|
628
|
+
modifier: args === null || args === void 0 ? void 0 : args.modifier,
|
|
629
|
+
container
|
|
630
|
+
} : {
|
|
631
|
+
container
|
|
632
|
+
});
|
|
633
|
+
}, {
|
|
634
|
+
...options,
|
|
635
|
+
id,
|
|
636
|
+
type: VARIANT_TYPES.MatchVariant,
|
|
637
|
+
variantInfo: VARIANT_INFO.Dynamic
|
|
638
|
+
});
|
|
453
639
|
}
|
|
454
640
|
};
|
|
641
|
+
return api;
|
|
455
642
|
}
|
|
456
643
|
let fileModifiedMapCache = new WeakMap();
|
|
457
644
|
function getFileModifiedMap(context) {
|
|
@@ -462,30 +649,34 @@ function getFileModifiedMap(context) {
|
|
|
462
649
|
}
|
|
463
650
|
function trackModified(files, fileModifiedMap) {
|
|
464
651
|
let changed = false;
|
|
652
|
+
let mtimesToCommit = new Map();
|
|
465
653
|
for (let file of files){
|
|
466
|
-
var
|
|
654
|
+
var _fs_statSync;
|
|
467
655
|
if (!file) continue;
|
|
468
656
|
let parsed = _url.default.parse(file);
|
|
469
|
-
let pathname = parsed.hash ? parsed.href.replace(parsed.hash,
|
|
470
|
-
pathname = parsed.search ? pathname.replace(parsed.search,
|
|
471
|
-
let newModified = (
|
|
657
|
+
let pathname = parsed.hash ? parsed.href.replace(parsed.hash, "") : parsed.href;
|
|
658
|
+
pathname = parsed.search ? pathname.replace(parsed.search, "") : pathname;
|
|
659
|
+
let newModified = (_fs_statSync = _fs.default.statSync(decodeURIComponent(pathname), {
|
|
472
660
|
throwIfNoEntry: false
|
|
473
|
-
})) === null ||
|
|
661
|
+
})) === null || _fs_statSync === void 0 ? void 0 : _fs_statSync.mtimeMs;
|
|
474
662
|
if (!newModified) {
|
|
475
663
|
continue;
|
|
476
664
|
}
|
|
477
665
|
if (!fileModifiedMap.has(file) || newModified > fileModifiedMap.get(file)) {
|
|
478
666
|
changed = true;
|
|
479
667
|
}
|
|
480
|
-
|
|
668
|
+
mtimesToCommit.set(file, newModified);
|
|
481
669
|
}
|
|
482
|
-
return
|
|
670
|
+
return [
|
|
671
|
+
changed,
|
|
672
|
+
mtimesToCommit
|
|
673
|
+
];
|
|
483
674
|
}
|
|
484
675
|
function extractVariantAtRules(node) {
|
|
485
676
|
node.walkAtRules((atRule)=>{
|
|
486
677
|
if ([
|
|
487
|
-
|
|
488
|
-
|
|
678
|
+
"responsive",
|
|
679
|
+
"variants"
|
|
489
680
|
].includes(atRule.name)) {
|
|
490
681
|
extractVariantAtRules(atRule);
|
|
491
682
|
atRule.before(atRule.nodes);
|
|
@@ -496,18 +687,18 @@ function extractVariantAtRules(node) {
|
|
|
496
687
|
function collectLayerPlugins(root) {
|
|
497
688
|
let layerPlugins = [];
|
|
498
689
|
root.each((node)=>{
|
|
499
|
-
if (node.type ===
|
|
500
|
-
|
|
501
|
-
|
|
690
|
+
if (node.type === "atrule" && [
|
|
691
|
+
"responsive",
|
|
692
|
+
"variants"
|
|
502
693
|
].includes(node.name)) {
|
|
503
|
-
node.name =
|
|
504
|
-
node.params =
|
|
694
|
+
node.name = "layer";
|
|
695
|
+
node.params = "utilities";
|
|
505
696
|
}
|
|
506
697
|
});
|
|
507
698
|
// Walk @layer rules and treat them like plugins
|
|
508
|
-
root.walkAtRules(
|
|
699
|
+
root.walkAtRules("layer", (layerRule)=>{
|
|
509
700
|
extractVariantAtRules(layerRule);
|
|
510
|
-
if (layerRule.params ===
|
|
701
|
+
if (layerRule.params === "base") {
|
|
511
702
|
for (let node of layerRule.nodes){
|
|
512
703
|
layerPlugins.push(function({ addBase }) {
|
|
513
704
|
addBase(node, {
|
|
@@ -516,36 +707,28 @@ function collectLayerPlugins(root) {
|
|
|
516
707
|
});
|
|
517
708
|
}
|
|
518
709
|
layerRule.remove();
|
|
519
|
-
} else if (layerRule.params ===
|
|
710
|
+
} else if (layerRule.params === "components") {
|
|
520
711
|
for (let node of layerRule.nodes){
|
|
521
712
|
layerPlugins.push(function({ addComponents }) {
|
|
522
713
|
addComponents(node, {
|
|
523
|
-
respectPrefix: false
|
|
714
|
+
respectPrefix: false,
|
|
715
|
+
preserveSource: true
|
|
524
716
|
});
|
|
525
717
|
});
|
|
526
718
|
}
|
|
527
719
|
layerRule.remove();
|
|
528
|
-
} else if (layerRule.params ===
|
|
720
|
+
} else if (layerRule.params === "utilities") {
|
|
529
721
|
for (let node of layerRule.nodes){
|
|
530
722
|
layerPlugins.push(function({ addUtilities }) {
|
|
531
723
|
addUtilities(node, {
|
|
532
|
-
respectPrefix: false
|
|
724
|
+
respectPrefix: false,
|
|
725
|
+
preserveSource: true
|
|
533
726
|
});
|
|
534
727
|
});
|
|
535
728
|
}
|
|
536
729
|
layerRule.remove();
|
|
537
730
|
}
|
|
538
731
|
});
|
|
539
|
-
root.walkRules((rule)=>{
|
|
540
|
-
// At this point it is safe to include all the left-over css from the
|
|
541
|
-
// user's css file. This is because the `@tailwind` and `@layer` directives
|
|
542
|
-
// will already be handled and will be removed from the css tree.
|
|
543
|
-
layerPlugins.push(function({ addUserCss }) {
|
|
544
|
-
addUserCss(rule, {
|
|
545
|
-
respectPrefix: false
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
});
|
|
549
732
|
return layerPlugins;
|
|
550
733
|
}
|
|
551
734
|
function resolvePlugins(context, root) {
|
|
@@ -562,23 +745,46 @@ function resolvePlugins(context, root) {
|
|
|
562
745
|
if (plugin.__isOptionsFunction) {
|
|
563
746
|
plugin = plugin();
|
|
564
747
|
}
|
|
565
|
-
return typeof plugin ===
|
|
748
|
+
return typeof plugin === "function" ? plugin : plugin.handler;
|
|
566
749
|
});
|
|
567
750
|
let layerPlugins = collectLayerPlugins(root);
|
|
568
751
|
// TODO: This is a workaround for backwards compatibility, since custom variants
|
|
569
752
|
// were historically sorted before screen/stackable variants.
|
|
570
753
|
let beforeVariants = [
|
|
571
|
-
_corePlugins.variantPlugins[
|
|
572
|
-
_corePlugins.variantPlugins[
|
|
754
|
+
_corePlugins.variantPlugins["childVariant"],
|
|
755
|
+
_corePlugins.variantPlugins["pseudoElementVariants"],
|
|
756
|
+
_corePlugins.variantPlugins["pseudoClassVariants"],
|
|
757
|
+
_corePlugins.variantPlugins["hasVariants"],
|
|
758
|
+
_corePlugins.variantPlugins["ariaVariants"],
|
|
759
|
+
_corePlugins.variantPlugins["dataVariants"]
|
|
573
760
|
];
|
|
574
761
|
let afterVariants = [
|
|
575
|
-
_corePlugins.variantPlugins[
|
|
576
|
-
_corePlugins.variantPlugins[
|
|
577
|
-
_corePlugins.variantPlugins[
|
|
578
|
-
_corePlugins.variantPlugins[
|
|
579
|
-
_corePlugins.variantPlugins[
|
|
580
|
-
_corePlugins.variantPlugins[
|
|
762
|
+
_corePlugins.variantPlugins["supportsVariants"],
|
|
763
|
+
_corePlugins.variantPlugins["reducedMotionVariants"],
|
|
764
|
+
_corePlugins.variantPlugins["prefersContrastVariants"],
|
|
765
|
+
_corePlugins.variantPlugins["screenVariants"],
|
|
766
|
+
_corePlugins.variantPlugins["orientationVariants"],
|
|
767
|
+
_corePlugins.variantPlugins["directionVariants"],
|
|
768
|
+
_corePlugins.variantPlugins["darkVariants"],
|
|
769
|
+
_corePlugins.variantPlugins["forcedColorsVariants"],
|
|
770
|
+
_corePlugins.variantPlugins["printVariant"]
|
|
581
771
|
];
|
|
772
|
+
// This is a compatibility fix for the pre 3.4 dark mode behavior
|
|
773
|
+
// `class` retains the old behavior, but `selector` keeps the new behavior
|
|
774
|
+
let isLegacyDarkMode = context.tailwindConfig.darkMode === "class" || Array.isArray(context.tailwindConfig.darkMode) && context.tailwindConfig.darkMode[0] === "class";
|
|
775
|
+
if (isLegacyDarkMode) {
|
|
776
|
+
afterVariants = [
|
|
777
|
+
_corePlugins.variantPlugins["supportsVariants"],
|
|
778
|
+
_corePlugins.variantPlugins["reducedMotionVariants"],
|
|
779
|
+
_corePlugins.variantPlugins["prefersContrastVariants"],
|
|
780
|
+
_corePlugins.variantPlugins["darkVariants"],
|
|
781
|
+
_corePlugins.variantPlugins["screenVariants"],
|
|
782
|
+
_corePlugins.variantPlugins["orientationVariants"],
|
|
783
|
+
_corePlugins.variantPlugins["directionVariants"],
|
|
784
|
+
_corePlugins.variantPlugins["forcedColorsVariants"],
|
|
785
|
+
_corePlugins.variantPlugins["printVariant"]
|
|
786
|
+
];
|
|
787
|
+
}
|
|
582
788
|
return [
|
|
583
789
|
...corePluginList,
|
|
584
790
|
...beforeVariants,
|
|
@@ -590,13 +796,9 @@ function resolvePlugins(context, root) {
|
|
|
590
796
|
function registerPlugins(plugins, context) {
|
|
591
797
|
let variantList = [];
|
|
592
798
|
let variantMap = new Map();
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
components: 0n,
|
|
597
|
-
utilities: 0n,
|
|
598
|
-
user: 0n
|
|
599
|
-
};
|
|
799
|
+
context.variantMap = variantMap;
|
|
800
|
+
let offsets = new _offsets.Offsets();
|
|
801
|
+
context.offsets = offsets;
|
|
600
802
|
let classList = new Set();
|
|
601
803
|
let pluginApi = buildPluginApi(context.tailwindConfig, context, {
|
|
602
804
|
variantList,
|
|
@@ -613,92 +815,80 @@ function registerPlugins(plugins, context) {
|
|
|
613
815
|
plugin === null || plugin === void 0 ? void 0 : plugin(pluginApi);
|
|
614
816
|
}
|
|
615
817
|
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
)([
|
|
619
|
-
offsets.base,
|
|
620
|
-
offsets.defaults,
|
|
621
|
-
offsets.components,
|
|
622
|
-
offsets.utilities,
|
|
623
|
-
offsets.user,
|
|
624
|
-
]);
|
|
625
|
-
let reservedBits = BigInt(highestOffset.toString(2).length);
|
|
626
|
-
// A number one less than the top range of the highest offset area
|
|
627
|
-
// so arbitrary properties are always sorted at the end.
|
|
628
|
-
context.arbitraryPropertiesSort = (1n << reservedBits << 0n) - 1n;
|
|
629
|
-
context.layerOrder = {
|
|
630
|
-
defaults: 1n << reservedBits << 0n,
|
|
631
|
-
base: 1n << reservedBits << 1n,
|
|
632
|
-
components: 1n << reservedBits << 2n,
|
|
633
|
-
utilities: 1n << reservedBits << 3n,
|
|
634
|
-
user: 1n << reservedBits << 4n
|
|
635
|
-
};
|
|
636
|
-
reservedBits += 5n;
|
|
637
|
-
let offset = 0;
|
|
638
|
-
context.variantOrder = new Map(variantList.map((variant, i)=>{
|
|
639
|
-
let variantFunctions = variantMap.get(variant).length;
|
|
640
|
-
let bits = 1n << BigInt(i + offset) << reservedBits;
|
|
641
|
-
offset += variantFunctions - 1;
|
|
642
|
-
return [
|
|
643
|
-
variant,
|
|
644
|
-
bits
|
|
645
|
-
];
|
|
646
|
-
}).sort(([, a], [, z])=>(0, _bigSign).default(a - z)
|
|
647
|
-
));
|
|
648
|
-
context.minimumScreen = [
|
|
649
|
-
...context.variantOrder.values()
|
|
650
|
-
].shift();
|
|
818
|
+
// Make sure to record bit masks for every variant
|
|
819
|
+
offsets.recordVariants(variantList, (variant)=>variantMap.get(variant).length);
|
|
651
820
|
// Build variantMap
|
|
652
|
-
for (let [variantName,
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
sort << BigInt(idx),
|
|
821
|
+
for (let [variantName, variantFunctions] of variantMap.entries()){
|
|
822
|
+
context.variantMap.set(variantName, variantFunctions.map((variantFunction, idx)=>[
|
|
823
|
+
offsets.forVariant(variantName, idx),
|
|
656
824
|
variantFunction
|
|
657
|
-
]
|
|
658
|
-
));
|
|
825
|
+
]));
|
|
659
826
|
}
|
|
660
|
-
var
|
|
661
|
-
let safelist = ((
|
|
827
|
+
var _context_tailwindConfig_safelist;
|
|
828
|
+
let safelist = ((_context_tailwindConfig_safelist = context.tailwindConfig.safelist) !== null && _context_tailwindConfig_safelist !== void 0 ? _context_tailwindConfig_safelist : []).filter(Boolean);
|
|
662
829
|
if (safelist.length > 0) {
|
|
663
830
|
let checks = [];
|
|
664
|
-
for (let
|
|
665
|
-
if (typeof
|
|
831
|
+
for (let value of safelist){
|
|
832
|
+
if (typeof value === "string") {
|
|
666
833
|
context.changedContent.push({
|
|
667
|
-
content:
|
|
668
|
-
extension:
|
|
834
|
+
content: value,
|
|
835
|
+
extension: "html"
|
|
669
836
|
});
|
|
670
837
|
continue;
|
|
671
838
|
}
|
|
672
|
-
if (
|
|
673
|
-
_log.default.warn(
|
|
674
|
-
|
|
675
|
-
|
|
839
|
+
if (value instanceof RegExp) {
|
|
840
|
+
_log.default.warn("root-regex", [
|
|
841
|
+
"Regular expressions in `safelist` work differently in Tailwind CSS v3.0.",
|
|
842
|
+
"Update your `safelist` configuration to eliminate this warning.",
|
|
843
|
+
"https://tailwindcss.com/docs/content-configuration#safelisting-classes"
|
|
676
844
|
]);
|
|
677
845
|
continue;
|
|
678
846
|
}
|
|
679
|
-
checks.push(
|
|
847
|
+
checks.push(value);
|
|
680
848
|
}
|
|
681
849
|
if (checks.length > 0) {
|
|
682
850
|
let patternMatchingCount = new Map();
|
|
851
|
+
let prefixLength = context.tailwindConfig.prefix.length;
|
|
852
|
+
let checkImportantUtils = checks.some((check)=>check.pattern.source.includes("!"));
|
|
683
853
|
for (let util of classList){
|
|
684
854
|
let utils = Array.isArray(util) ? (()=>{
|
|
685
855
|
let [utilName, options] = util;
|
|
686
|
-
var
|
|
687
|
-
let
|
|
688
|
-
|
|
689
|
-
);
|
|
856
|
+
var _options_values;
|
|
857
|
+
let values = Object.keys((_options_values = options === null || options === void 0 ? void 0 : options.values) !== null && _options_values !== void 0 ? _options_values : {});
|
|
858
|
+
let classes = values.map((value)=>(0, _nameClass.formatClass)(utilName, value));
|
|
690
859
|
if (options === null || options === void 0 ? void 0 : options.supportsNegativeValues) {
|
|
860
|
+
// This is the normal negated version
|
|
861
|
+
// e.g. `-inset-1` or `-tw-inset-1`
|
|
862
|
+
classes = [
|
|
863
|
+
...classes,
|
|
864
|
+
...classes.map((cls)=>"-" + cls)
|
|
865
|
+
];
|
|
866
|
+
// This is the negated version *after* the prefix
|
|
867
|
+
// e.g. `tw--inset-1`
|
|
868
|
+
// The prefix is already attached to util name
|
|
869
|
+
// So we add the negative after the prefix
|
|
691
870
|
classes = [
|
|
692
871
|
...classes,
|
|
693
|
-
...classes.map((cls)=>
|
|
694
|
-
|
|
872
|
+
...classes.map((cls)=>cls.slice(0, prefixLength) + "-" + cls.slice(prefixLength))
|
|
873
|
+
];
|
|
874
|
+
}
|
|
875
|
+
if (options.types.some(({ type })=>type === "color")) {
|
|
876
|
+
classes = [
|
|
877
|
+
...classes,
|
|
878
|
+
...classes.flatMap((cls)=>Object.keys(context.tailwindConfig.theme.opacity).map((opacity)=>`${cls}/${opacity}`))
|
|
879
|
+
];
|
|
880
|
+
}
|
|
881
|
+
if (checkImportantUtils && (options === null || options === void 0 ? void 0 : options.respectImportant)) {
|
|
882
|
+
classes = [
|
|
883
|
+
...classes,
|
|
884
|
+
...classes.map((cls)=>"!" + cls)
|
|
695
885
|
];
|
|
696
886
|
}
|
|
697
887
|
return classes;
|
|
698
888
|
})() : [
|
|
699
889
|
util
|
|
700
890
|
];
|
|
701
|
-
for (let
|
|
891
|
+
for (let util of utils){
|
|
702
892
|
for (let { pattern , variants =[] } of checks){
|
|
703
893
|
// RegExp with the /g flag are stateful, so let's reset the last
|
|
704
894
|
// index pointer to reset the state.
|
|
@@ -706,16 +896,16 @@ function registerPlugins(plugins, context) {
|
|
|
706
896
|
if (!patternMatchingCount.has(pattern)) {
|
|
707
897
|
patternMatchingCount.set(pattern, 0);
|
|
708
898
|
}
|
|
709
|
-
if (!pattern.test(
|
|
899
|
+
if (!pattern.test(util)) continue;
|
|
710
900
|
patternMatchingCount.set(pattern, patternMatchingCount.get(pattern) + 1);
|
|
711
901
|
context.changedContent.push({
|
|
712
|
-
content:
|
|
713
|
-
extension:
|
|
902
|
+
content: util,
|
|
903
|
+
extension: "html"
|
|
714
904
|
});
|
|
715
905
|
for (let variant of variants){
|
|
716
906
|
context.changedContent.push({
|
|
717
|
-
content: variant + context.tailwindConfig.separator +
|
|
718
|
-
extension:
|
|
907
|
+
content: variant + context.tailwindConfig.separator + util,
|
|
908
|
+
extension: "html"
|
|
719
909
|
});
|
|
720
910
|
}
|
|
721
911
|
}
|
|
@@ -725,25 +915,101 @@ function registerPlugins(plugins, context) {
|
|
|
725
915
|
if (count !== 0) continue;
|
|
726
916
|
_log.default.warn([
|
|
727
917
|
`The safelist pattern \`${regex}\` doesn't match any Tailwind CSS classes.`,
|
|
728
|
-
|
|
918
|
+
"Fix this pattern or remove it from your `safelist` configuration.",
|
|
919
|
+
"https://tailwindcss.com/docs/content-configuration#safelisting-classes"
|
|
729
920
|
]);
|
|
730
921
|
}
|
|
731
922
|
}
|
|
732
923
|
}
|
|
924
|
+
var _context_tailwindConfig_darkMode, _concat_;
|
|
925
|
+
let darkClassName = (_concat_ = [].concat((_context_tailwindConfig_darkMode = context.tailwindConfig.darkMode) !== null && _context_tailwindConfig_darkMode !== void 0 ? _context_tailwindConfig_darkMode : "media")[1]) !== null && _concat_ !== void 0 ? _concat_ : "dark";
|
|
926
|
+
// A list of utilities that are used by certain Tailwind CSS utilities but
|
|
927
|
+
// that don't exist on their own. This will result in them "not existing" and
|
|
928
|
+
// sorting could be weird since you still require them in order to make the
|
|
929
|
+
// host utilities work properly. (Thanks Biology)
|
|
930
|
+
let parasiteUtilities = [
|
|
931
|
+
prefix(context, darkClassName),
|
|
932
|
+
prefix(context, "group"),
|
|
933
|
+
prefix(context, "peer")
|
|
934
|
+
];
|
|
935
|
+
context.getClassOrder = function getClassOrder(classes) {
|
|
936
|
+
// Sort classes so they're ordered in a deterministic manner
|
|
937
|
+
let sorted = [
|
|
938
|
+
...classes
|
|
939
|
+
].sort((a, z)=>{
|
|
940
|
+
if (a === z) return 0;
|
|
941
|
+
if (a < z) return -1;
|
|
942
|
+
return 1;
|
|
943
|
+
});
|
|
944
|
+
// Non-util classes won't be generated, so we default them to null
|
|
945
|
+
let sortedClassNames = new Map(sorted.map((className)=>[
|
|
946
|
+
className,
|
|
947
|
+
null
|
|
948
|
+
]));
|
|
949
|
+
// Sort all classes in order
|
|
950
|
+
// Non-tailwind classes won't be generated and will be left as `null`
|
|
951
|
+
let rules = (0, _generateRules.generateRules)(new Set(sorted), context, true);
|
|
952
|
+
rules = context.offsets.sort(rules);
|
|
953
|
+
let idx = BigInt(parasiteUtilities.length);
|
|
954
|
+
for (const [, rule] of rules){
|
|
955
|
+
let candidate = rule.raws.tailwind.candidate;
|
|
956
|
+
var _sortedClassNames_get;
|
|
957
|
+
// When multiple rules match a candidate
|
|
958
|
+
// always take the position of the first one
|
|
959
|
+
sortedClassNames.set(candidate, (_sortedClassNames_get = sortedClassNames.get(candidate)) !== null && _sortedClassNames_get !== void 0 ? _sortedClassNames_get : idx++);
|
|
960
|
+
}
|
|
961
|
+
return classes.map((className)=>{
|
|
962
|
+
var _sortedClassNames_get;
|
|
963
|
+
let order = (_sortedClassNames_get = sortedClassNames.get(className)) !== null && _sortedClassNames_get !== void 0 ? _sortedClassNames_get : null;
|
|
964
|
+
let parasiteIndex = parasiteUtilities.indexOf(className);
|
|
965
|
+
if (order === null && parasiteIndex !== -1) {
|
|
966
|
+
// This will make sure that it is at the very beginning of the
|
|
967
|
+
// `components` layer which technically means 'before any
|
|
968
|
+
// components'.
|
|
969
|
+
order = BigInt(parasiteIndex);
|
|
970
|
+
}
|
|
971
|
+
return [
|
|
972
|
+
className,
|
|
973
|
+
order
|
|
974
|
+
];
|
|
975
|
+
});
|
|
976
|
+
};
|
|
733
977
|
// Generate a list of strings for autocompletion purposes, e.g.
|
|
734
978
|
// ['uppercase', 'lowercase', ...]
|
|
735
|
-
context.getClassList = function() {
|
|
979
|
+
context.getClassList = function getClassList(options = {}) {
|
|
736
980
|
let output = [];
|
|
737
981
|
for (let util of classList){
|
|
738
982
|
if (Array.isArray(util)) {
|
|
739
|
-
|
|
983
|
+
var _utilOptions_types;
|
|
984
|
+
let [utilName, utilOptions] = util;
|
|
740
985
|
let negativeClasses = [];
|
|
741
|
-
var
|
|
742
|
-
|
|
743
|
-
})){
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
986
|
+
var _utilOptions_modifiers;
|
|
987
|
+
let modifiers = Object.keys((_utilOptions_modifiers = utilOptions === null || utilOptions === void 0 ? void 0 : utilOptions.modifiers) !== null && _utilOptions_modifiers !== void 0 ? _utilOptions_modifiers : {});
|
|
988
|
+
if (utilOptions === null || utilOptions === void 0 ? void 0 : (_utilOptions_types = utilOptions.types) === null || _utilOptions_types === void 0 ? void 0 : _utilOptions_types.some(({ type })=>type === "color")) {
|
|
989
|
+
var _context_tailwindConfig_theme_opacity;
|
|
990
|
+
modifiers.push(...Object.keys((_context_tailwindConfig_theme_opacity = context.tailwindConfig.theme.opacity) !== null && _context_tailwindConfig_theme_opacity !== void 0 ? _context_tailwindConfig_theme_opacity : {}));
|
|
991
|
+
}
|
|
992
|
+
let metadata = {
|
|
993
|
+
modifiers
|
|
994
|
+
};
|
|
995
|
+
let includeMetadata = options.includeMetadata && modifiers.length > 0;
|
|
996
|
+
var _utilOptions_values;
|
|
997
|
+
for (let [key, value] of Object.entries((_utilOptions_values = utilOptions === null || utilOptions === void 0 ? void 0 : utilOptions.values) !== null && _utilOptions_values !== void 0 ? _utilOptions_values : {})){
|
|
998
|
+
// Ignore undefined and null values
|
|
999
|
+
if (value == null) {
|
|
1000
|
+
continue;
|
|
1001
|
+
}
|
|
1002
|
+
let cls = (0, _nameClass.formatClass)(utilName, key);
|
|
1003
|
+
output.push(includeMetadata ? [
|
|
1004
|
+
cls,
|
|
1005
|
+
metadata
|
|
1006
|
+
] : cls);
|
|
1007
|
+
if ((utilOptions === null || utilOptions === void 0 ? void 0 : utilOptions.supportsNegativeValues) && (0, _negateValue.default)(value)) {
|
|
1008
|
+
let cls = (0, _nameClass.formatClass)(utilName, `-${key}`);
|
|
1009
|
+
negativeClasses.push(includeMetadata ? [
|
|
1010
|
+
cls,
|
|
1011
|
+
metadata
|
|
1012
|
+
] : cls);
|
|
747
1013
|
}
|
|
748
1014
|
}
|
|
749
1015
|
output.push(...negativeClasses);
|
|
@@ -753,32 +1019,215 @@ function registerPlugins(plugins, context) {
|
|
|
753
1019
|
}
|
|
754
1020
|
return output;
|
|
755
1021
|
};
|
|
1022
|
+
// Generate a list of available variants with meta information of the type of variant.
|
|
1023
|
+
context.getVariants = function getVariants() {
|
|
1024
|
+
// We use a unique, random ID for candidate names to avoid conflicts
|
|
1025
|
+
// We can't use characters like `_`, `:`, `@` or `.` because they might
|
|
1026
|
+
// be used as a separator
|
|
1027
|
+
let id = Math.random().toString(36).substring(7).toUpperCase();
|
|
1028
|
+
let result = [];
|
|
1029
|
+
for (let [name, options] of context.variantOptions.entries()){
|
|
1030
|
+
if (options.variantInfo === VARIANT_INFO.Base) continue;
|
|
1031
|
+
var _options_values;
|
|
1032
|
+
result.push({
|
|
1033
|
+
name,
|
|
1034
|
+
isArbitrary: options.type === Symbol.for("MATCH_VARIANT"),
|
|
1035
|
+
values: Object.keys((_options_values = options.values) !== null && _options_values !== void 0 ? _options_values : {}),
|
|
1036
|
+
hasDash: name !== "@",
|
|
1037
|
+
selectors ({ modifier , value } = {}) {
|
|
1038
|
+
let candidate = `TAILWINDPLACEHOLDER${id}`;
|
|
1039
|
+
let rule = _postcss.default.rule({
|
|
1040
|
+
selector: `.${candidate}`
|
|
1041
|
+
});
|
|
1042
|
+
let container = _postcss.default.root({
|
|
1043
|
+
nodes: [
|
|
1044
|
+
rule.clone()
|
|
1045
|
+
]
|
|
1046
|
+
});
|
|
1047
|
+
let before = container.toString();
|
|
1048
|
+
var _context_variantMap_get;
|
|
1049
|
+
let fns = ((_context_variantMap_get = context.variantMap.get(name)) !== null && _context_variantMap_get !== void 0 ? _context_variantMap_get : []).flatMap(([_, fn])=>fn);
|
|
1050
|
+
let formatStrings = [];
|
|
1051
|
+
for (let fn of fns){
|
|
1052
|
+
var _options_values;
|
|
1053
|
+
let localFormatStrings = [];
|
|
1054
|
+
var _options_values_value;
|
|
1055
|
+
let api = {
|
|
1056
|
+
args: {
|
|
1057
|
+
modifier,
|
|
1058
|
+
value: (_options_values_value = (_options_values = options.values) === null || _options_values === void 0 ? void 0 : _options_values[value]) !== null && _options_values_value !== void 0 ? _options_values_value : value
|
|
1059
|
+
},
|
|
1060
|
+
separator: context.tailwindConfig.separator,
|
|
1061
|
+
modifySelectors (modifierFunction) {
|
|
1062
|
+
// Run the modifierFunction over each rule
|
|
1063
|
+
container.each((rule)=>{
|
|
1064
|
+
if (rule.type !== "rule") {
|
|
1065
|
+
return;
|
|
1066
|
+
}
|
|
1067
|
+
rule.selectors = rule.selectors.map((selector)=>{
|
|
1068
|
+
return modifierFunction({
|
|
1069
|
+
get className () {
|
|
1070
|
+
return (0, _generateRules.getClassNameFromSelector)(selector);
|
|
1071
|
+
},
|
|
1072
|
+
selector
|
|
1073
|
+
});
|
|
1074
|
+
});
|
|
1075
|
+
});
|
|
1076
|
+
return container;
|
|
1077
|
+
},
|
|
1078
|
+
format (str) {
|
|
1079
|
+
localFormatStrings.push(str);
|
|
1080
|
+
},
|
|
1081
|
+
wrap (wrapper) {
|
|
1082
|
+
localFormatStrings.push(`@${wrapper.name} ${wrapper.params} { & }`);
|
|
1083
|
+
},
|
|
1084
|
+
container
|
|
1085
|
+
};
|
|
1086
|
+
let ruleWithVariant = fn(api);
|
|
1087
|
+
if (localFormatStrings.length > 0) {
|
|
1088
|
+
formatStrings.push(localFormatStrings);
|
|
1089
|
+
}
|
|
1090
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
1091
|
+
for (let variantFunction of ruleWithVariant){
|
|
1092
|
+
localFormatStrings = [];
|
|
1093
|
+
variantFunction(api);
|
|
1094
|
+
formatStrings.push(localFormatStrings);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
// Reverse engineer the result of the `container`
|
|
1099
|
+
let manualFormatStrings = [];
|
|
1100
|
+
let after = container.toString();
|
|
1101
|
+
if (before !== after) {
|
|
1102
|
+
// Figure out all selectors
|
|
1103
|
+
container.walkRules((rule)=>{
|
|
1104
|
+
let modified = rule.selector;
|
|
1105
|
+
// Rebuild the base selector, this is what plugin authors would do
|
|
1106
|
+
// as well. E.g.: `${variant}${separator}${className}`.
|
|
1107
|
+
// However, plugin authors probably also prepend or append certain
|
|
1108
|
+
// classes, pseudos, ids, ...
|
|
1109
|
+
let rebuiltBase = (0, _postcssselectorparser.default)((selectors)=>{
|
|
1110
|
+
selectors.walkClasses((classNode)=>{
|
|
1111
|
+
classNode.value = `${name}${context.tailwindConfig.separator}${classNode.value}`;
|
|
1112
|
+
});
|
|
1113
|
+
}).processSync(modified);
|
|
1114
|
+
// Now that we know the original selector, the new selector, and
|
|
1115
|
+
// the rebuild part in between, we can replace the part that plugin
|
|
1116
|
+
// authors need to rebuild with `&`, and eventually store it in the
|
|
1117
|
+
// collectedFormats. Similar to what `format('...')` would do.
|
|
1118
|
+
//
|
|
1119
|
+
// E.g.:
|
|
1120
|
+
// variant: foo
|
|
1121
|
+
// selector: .markdown > p
|
|
1122
|
+
// modified (by plugin): .foo .foo\\:markdown > p
|
|
1123
|
+
// rebuiltBase (internal): .foo\\:markdown > p
|
|
1124
|
+
// format: .foo &
|
|
1125
|
+
manualFormatStrings.push(modified.replace(rebuiltBase, "&").replace(candidate, "&"));
|
|
1126
|
+
});
|
|
1127
|
+
// Figure out all atrules
|
|
1128
|
+
container.walkAtRules((atrule)=>{
|
|
1129
|
+
manualFormatStrings.push(`@${atrule.name} (${atrule.params}) { & }`);
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
var _options_values1;
|
|
1133
|
+
let isArbitraryVariant = !(value in ((_options_values1 = options.values) !== null && _options_values1 !== void 0 ? _options_values1 : {}));
|
|
1134
|
+
var _options_INTERNAL_FEATURES;
|
|
1135
|
+
let internalFeatures = (_options_INTERNAL_FEATURES = options[INTERNAL_FEATURES]) !== null && _options_INTERNAL_FEATURES !== void 0 ? _options_INTERNAL_FEATURES : {};
|
|
1136
|
+
let respectPrefix = (()=>{
|
|
1137
|
+
if (isArbitraryVariant) return false;
|
|
1138
|
+
if (internalFeatures.respectPrefix === false) return false;
|
|
1139
|
+
return true;
|
|
1140
|
+
})();
|
|
1141
|
+
formatStrings = formatStrings.map((format)=>format.map((str)=>({
|
|
1142
|
+
format: str,
|
|
1143
|
+
respectPrefix
|
|
1144
|
+
})));
|
|
1145
|
+
manualFormatStrings = manualFormatStrings.map((format)=>({
|
|
1146
|
+
format,
|
|
1147
|
+
respectPrefix
|
|
1148
|
+
}));
|
|
1149
|
+
let opts = {
|
|
1150
|
+
candidate,
|
|
1151
|
+
context
|
|
1152
|
+
};
|
|
1153
|
+
let result = formatStrings.map((formats)=>(0, _formatVariantSelector.finalizeSelector)(`.${candidate}`, (0, _formatVariantSelector.formatVariantSelector)(formats, opts), opts).replace(`.${candidate}`, "&").replace("{ & }", "").trim());
|
|
1154
|
+
if (manualFormatStrings.length > 0) {
|
|
1155
|
+
result.push((0, _formatVariantSelector.formatVariantSelector)(manualFormatStrings, opts).toString().replace(`.${candidate}`, "&"));
|
|
1156
|
+
}
|
|
1157
|
+
return result;
|
|
1158
|
+
}
|
|
1159
|
+
});
|
|
1160
|
+
}
|
|
1161
|
+
return result;
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* Mark as class as retroactively invalid
|
|
1166
|
+
*
|
|
1167
|
+
*
|
|
1168
|
+
* @param {string} candidate
|
|
1169
|
+
*/ function markInvalidUtilityCandidate(context, candidate) {
|
|
1170
|
+
if (!context.classCache.has(candidate)) {
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
// Mark this as not being a real utility
|
|
1174
|
+
context.notClassCache.add(candidate);
|
|
1175
|
+
// Remove it from any candidate-specific caches
|
|
1176
|
+
context.classCache.delete(candidate);
|
|
1177
|
+
context.applyClassCache.delete(candidate);
|
|
1178
|
+
context.candidateRuleMap.delete(candidate);
|
|
1179
|
+
context.candidateRuleCache.delete(candidate);
|
|
1180
|
+
// Ensure the stylesheet gets rebuilt
|
|
1181
|
+
context.stylesheetCache = null;
|
|
1182
|
+
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Mark as class as retroactively invalid
|
|
1185
|
+
*
|
|
1186
|
+
* @param {import('postcss').Node} node
|
|
1187
|
+
*/ function markInvalidUtilityNode(context, node) {
|
|
1188
|
+
let candidate = node.raws.tailwind.candidate;
|
|
1189
|
+
if (!candidate) {
|
|
1190
|
+
return;
|
|
1191
|
+
}
|
|
1192
|
+
for (const entry of context.ruleCache){
|
|
1193
|
+
if (entry[1].raws.tailwind.candidate === candidate) {
|
|
1194
|
+
context.ruleCache.delete(entry);
|
|
1195
|
+
// context.postCssNodeCache.delete(node)
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
markInvalidUtilityCandidate(context, candidate);
|
|
756
1199
|
}
|
|
757
1200
|
function createContext(tailwindConfig, changedContent = [], root = _postcss.default.root()) {
|
|
1201
|
+
var _tailwindConfig_blocklist;
|
|
758
1202
|
let context = {
|
|
759
1203
|
disposables: [],
|
|
760
1204
|
ruleCache: new Set(),
|
|
1205
|
+
candidateRuleCache: new Map(),
|
|
761
1206
|
classCache: new Map(),
|
|
762
1207
|
applyClassCache: new Map(),
|
|
763
|
-
|
|
1208
|
+
// Seed the not class cache with the blocklist (which is only strings)
|
|
1209
|
+
notClassCache: new Set((_tailwindConfig_blocklist = tailwindConfig.blocklist) !== null && _tailwindConfig_blocklist !== void 0 ? _tailwindConfig_blocklist : []),
|
|
764
1210
|
postCssNodeCache: new Map(),
|
|
765
1211
|
candidateRuleMap: new Map(),
|
|
766
1212
|
tailwindConfig,
|
|
767
1213
|
changedContent: changedContent,
|
|
768
1214
|
variantMap: new Map(),
|
|
769
|
-
stylesheetCache: null
|
|
1215
|
+
stylesheetCache: null,
|
|
1216
|
+
variantOptions: new Map(),
|
|
1217
|
+
markInvalidUtilityCandidate: (candidate)=>markInvalidUtilityCandidate(context, candidate),
|
|
1218
|
+
markInvalidUtilityNode: (node)=>markInvalidUtilityNode(context, node)
|
|
770
1219
|
};
|
|
771
1220
|
let resolvedPlugins = resolvePlugins(context, root);
|
|
772
1221
|
registerPlugins(resolvedPlugins, context);
|
|
773
1222
|
return context;
|
|
774
1223
|
}
|
|
775
|
-
let contextMap =
|
|
776
|
-
let configContextMap =
|
|
777
|
-
let contextSourcesMap =
|
|
1224
|
+
let contextMap = _sharedState.contextMap;
|
|
1225
|
+
let configContextMap = _sharedState.configContextMap;
|
|
1226
|
+
let contextSourcesMap = _sharedState.contextSourcesMap;
|
|
778
1227
|
function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfigHash, contextDependencies) {
|
|
779
1228
|
let sourcePath = result.opts.from;
|
|
780
1229
|
let isConfigFile = userConfigPath !== null;
|
|
781
|
-
|
|
1230
|
+
_sharedState.env.DEBUG && console.log("Source path:", sourcePath);
|
|
782
1231
|
let existingContext;
|
|
783
1232
|
if (isConfigFile && contextMap.has(sourcePath)) {
|
|
784
1233
|
existingContext = contextMap.get(sourcePath);
|
|
@@ -788,16 +1237,18 @@ function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfig
|
|
|
788
1237
|
contextMap.set(sourcePath, context);
|
|
789
1238
|
existingContext = context;
|
|
790
1239
|
}
|
|
1240
|
+
let cssDidChange = (0, _cacheInvalidation.hasContentChanged)(sourcePath, root);
|
|
791
1241
|
// If there's already a context in the cache and we don't need to
|
|
792
1242
|
// reset the context, return the cached context.
|
|
793
1243
|
if (existingContext) {
|
|
794
|
-
let contextDependenciesChanged = trackModified([
|
|
1244
|
+
let [contextDependenciesChanged, mtimesToCommit] = trackModified([
|
|
795
1245
|
...contextDependencies
|
|
796
1246
|
], getFileModifiedMap(existingContext));
|
|
797
|
-
if (!contextDependenciesChanged) {
|
|
1247
|
+
if (!contextDependenciesChanged && !cssDidChange) {
|
|
798
1248
|
return [
|
|
799
1249
|
existingContext,
|
|
800
|
-
false
|
|
1250
|
+
false,
|
|
1251
|
+
mtimesToCommit
|
|
801
1252
|
];
|
|
802
1253
|
}
|
|
803
1254
|
}
|
|
@@ -823,9 +1274,12 @@ function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfig
|
|
|
823
1274
|
}
|
|
824
1275
|
}
|
|
825
1276
|
}
|
|
826
|
-
|
|
1277
|
+
_sharedState.env.DEBUG && console.log("Setting up new context...");
|
|
827
1278
|
let context = createContext(tailwindConfig, [], root);
|
|
828
|
-
|
|
1279
|
+
Object.assign(context, {
|
|
1280
|
+
userConfigPath
|
|
1281
|
+
});
|
|
1282
|
+
let [, mtimesToCommit] = trackModified([
|
|
829
1283
|
...contextDependencies
|
|
830
1284
|
], getFileModifiedMap(context));
|
|
831
1285
|
// ---
|
|
@@ -838,6 +1292,7 @@ function getContext(root, result, tailwindConfig, userConfigPath, tailwindConfig
|
|
|
838
1292
|
contextSourcesMap.get(context).add(sourcePath);
|
|
839
1293
|
return [
|
|
840
1294
|
context,
|
|
841
|
-
true
|
|
1295
|
+
true,
|
|
1296
|
+
mtimesToCommit
|
|
842
1297
|
];
|
|
843
1298
|
}
|