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