tailwindcss 0.0.0-insiders.fc25299 → 0.0.0-insiders.fca7085
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -3
- package/lib/cli-peer-dependencies.js +4 -0
- package/lib/cli.js +9 -2
- package/lib/corePlugins.js +42 -25
- package/lib/featureFlags.js +6 -2
- package/lib/lib/defaultExtractor.js +45 -29
- package/lib/lib/evaluateTailwindFunctions.js +15 -3
- package/lib/lib/generateRules.js +34 -3
- package/lib/lib/setupContextUtils.js +62 -55
- package/lib/util/formatVariantSelector.js +12 -14
- package/lib/util/getAllConfigs.js +8 -0
- package/lib/util/resolveConfig.js +49 -21
- package/lib/util/transformThemeValue.js +4 -2
- package/package.json +11 -9
- package/peers/index.js +3204 -1292
- package/plugin.d.ts +10 -5
- package/src/cli-peer-dependencies.js +4 -0
- package/src/cli.js +14 -2
- package/src/corePlugins.js +46 -23
- package/src/featureFlags.js +2 -2
- package/src/lib/defaultExtractor.js +52 -40
- package/src/lib/evaluateTailwindFunctions.js +18 -4
- package/src/lib/generateRules.js +37 -3
- package/src/lib/setupContextUtils.js +61 -54
- package/src/util/formatVariantSelector.js +19 -13
- package/src/util/getAllConfigs.js +7 -0
- package/src/util/resolveConfig.js +63 -21
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +4 -2
- package/stubs/defaultConfig.stub.js +1 -1
- package/types/config.d.ts +25 -23
package/CHANGELOG.md
CHANGED
|
@@ -23,14 +23,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
23
23
|
- Move `important` selector to the front when `@apply`-ing selector-modifying variants in custom utilities ([#8313](https://github.com/tailwindlabs/tailwindcss/pull/8313))
|
|
24
24
|
- Error when registering an invalid custom variant ([#8345](https://github.com/tailwindlabs/tailwindcss/pull/8345))
|
|
25
25
|
- Create tailwind.config.cjs file in ESM package when running init ([#8363](https://github.com/tailwindlabs/tailwindcss/pull/8363))
|
|
26
|
+
- Fix `matchVariants` that use at-rules and placeholders ([#8392](https://github.com/tailwindlabs/tailwindcss/pull/8392))
|
|
27
|
+
- Improve types of the `tailwindcss/plugin` ([#8400](https://github.com/tailwindlabs/tailwindcss/pull/8400))
|
|
28
|
+
- Allow returning parallel variants from `addVariant` or `matchVariant` callback functions ([#8455](https://github.com/tailwindlabs/tailwindcss/pull/8455))
|
|
29
|
+
- Try using local `postcss` installation first in the CLI ([#8270](https://github.com/tailwindlabs/tailwindcss/pull/8270))
|
|
30
|
+
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
|
|
26
31
|
|
|
27
32
|
### Changed
|
|
28
33
|
|
|
29
|
-
-
|
|
34
|
+
- Only apply hover styles when supported (future) ([#8394](https://github.com/tailwindlabs/tailwindcss/pull/8394))
|
|
35
|
+
- Respect default ring color opacity (future) ([#8448](https://github.com/tailwindlabs/tailwindcss/pull/8448), [3f4005e](https://github.com/tailwindlabs/tailwindcss/commit/3f4005e833445f7549219eb5ae89728cbb3a2630))
|
|
30
36
|
|
|
31
37
|
### Added
|
|
32
38
|
|
|
33
|
-
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
|
|
34
39
|
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
|
|
35
40
|
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
|
|
36
41
|
- Add `text-start` and `text-end` utilities ([#6656](https://github.com/tailwindlabs/tailwindcss/pull/6656))
|
|
@@ -43,7 +48,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
43
48
|
- Add `grid-flow-dense` utility ([#8193](https://github.com/tailwindlabs/tailwindcss/pull/8193))
|
|
44
49
|
- Add `mix-blend-plus-lighter` utility ([#8288](https://github.com/tailwindlabs/tailwindcss/pull/8288))
|
|
45
50
|
- Add arbitrary variants ([#8299](https://github.com/tailwindlabs/tailwindcss/pull/8299))
|
|
46
|
-
- Add `matchVariant` API ([#8310](https://github.com/tailwindlabs/tailwindcss/pull/8310))
|
|
51
|
+
- Add experimental `matchVariant` API ([#8310](https://github.com/tailwindlabs/tailwindcss/pull/8310), [34fd0fb8](https://github.com/tailwindlabs/tailwindcss/commit/34fd0fb82aa574cddc5c7aa3ad7d1af5e3735e5d))
|
|
52
|
+
- Add `prefers-contrast` media query variants ([#8410](https://github.com/tailwindlabs/tailwindcss/pull/8410))
|
|
53
|
+
- Add opacity support when referencing colors with `theme` function ([#8416](https://github.com/tailwindlabs/tailwindcss/pull/8416))
|
|
54
|
+
- Add `postcss-import` support to the CLI ([#8437](https://github.com/tailwindlabs/tailwindcss/pull/8437))
|
|
55
|
+
- Add `optional` variant ([#8486](https://github.com/tailwindlabs/tailwindcss/pull/8486))
|
|
47
56
|
|
|
48
57
|
## [3.0.24] - 2022-04-12
|
|
49
58
|
|
|
@@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.lazyPostcss = lazyPostcss;
|
|
6
|
+
exports.lazyPostcssImport = lazyPostcssImport;
|
|
6
7
|
exports.lazyAutoprefixer = lazyAutoprefixer;
|
|
7
8
|
exports.lazyCssnano = lazyCssnano;
|
|
8
9
|
function lazyPostcss() {
|
|
9
10
|
return require("postcss");
|
|
10
11
|
}
|
|
12
|
+
function lazyPostcssImport() {
|
|
13
|
+
return require("postcss-import");
|
|
14
|
+
}
|
|
11
15
|
function lazyAutoprefixer() {
|
|
12
16
|
return require("autoprefixer");
|
|
13
17
|
}
|
package/lib/cli.js
CHANGED
|
@@ -523,9 +523,16 @@ async function build() {
|
|
|
523
523
|
};
|
|
524
524
|
tailwindPlugin.postcss = true;
|
|
525
525
|
let [beforePlugins, afterPlugins, postcssOptions] = includePostCss ? await loadPostCssPlugins() : [
|
|
526
|
+
[
|
|
527
|
+
(()=>{
|
|
528
|
+
try {
|
|
529
|
+
return require("postcss-import");
|
|
530
|
+
} catch {}
|
|
531
|
+
return (0, _indexJs).lazyPostcssImport();
|
|
532
|
+
})(),
|
|
533
|
+
],
|
|
526
534
|
[],
|
|
527
|
-
|
|
528
|
-
{}
|
|
535
|
+
{},
|
|
529
536
|
];
|
|
530
537
|
let plugins = [
|
|
531
538
|
...beforePlugins,
|
package/lib/corePlugins.js
CHANGED
|
@@ -19,6 +19,7 @@ var _packageJson = require("../package.json");
|
|
|
19
19
|
var _log = _interopRequireDefault(require("./util/log"));
|
|
20
20
|
var _normalizeScreens = require("./util/normalizeScreens");
|
|
21
21
|
var _parseBoxShadowValue = require("./util/parseBoxShadowValue");
|
|
22
|
+
var _featureFlags = require("./featureFlags");
|
|
22
23
|
function _interopRequireDefault(obj) {
|
|
23
24
|
return obj && obj.__esModule ? obj : {
|
|
24
25
|
default: obj
|
|
@@ -91,28 +92,28 @@ let variantPlugins = {
|
|
|
91
92
|
return "&::after";
|
|
92
93
|
});
|
|
93
94
|
},
|
|
94
|
-
pseudoClassVariants: ({ addVariant })=>{
|
|
95
|
+
pseudoClassVariants: ({ addVariant , config })=>{
|
|
95
96
|
let pseudoVariants = [
|
|
96
97
|
// Positional
|
|
97
98
|
[
|
|
98
99
|
"first",
|
|
99
|
-
"
|
|
100
|
+
"&:first-child"
|
|
100
101
|
],
|
|
101
102
|
[
|
|
102
103
|
"last",
|
|
103
|
-
"
|
|
104
|
+
"&:last-child"
|
|
104
105
|
],
|
|
105
106
|
[
|
|
106
107
|
"only",
|
|
107
|
-
"
|
|
108
|
+
"&:only-child"
|
|
108
109
|
],
|
|
109
110
|
[
|
|
110
111
|
"odd",
|
|
111
|
-
"
|
|
112
|
+
"&:nth-child(odd)"
|
|
112
113
|
],
|
|
113
114
|
[
|
|
114
115
|
"even",
|
|
115
|
-
"
|
|
116
|
+
"&:nth-child(even)"
|
|
116
117
|
],
|
|
117
118
|
"first-of-type",
|
|
118
119
|
"last-of-type",
|
|
@@ -137,13 +138,13 @@ let variantPlugins = {
|
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
});
|
|
140
|
-
return "
|
|
141
|
+
return "&:visited";
|
|
141
142
|
},
|
|
142
143
|
],
|
|
143
144
|
"target",
|
|
144
145
|
[
|
|
145
146
|
"open",
|
|
146
|
-
"[open]"
|
|
147
|
+
"&[open]"
|
|
147
148
|
],
|
|
148
149
|
// Forms
|
|
149
150
|
"default",
|
|
@@ -151,6 +152,7 @@ let variantPlugins = {
|
|
|
151
152
|
"indeterminate",
|
|
152
153
|
"placeholder-shown",
|
|
153
154
|
"autofill",
|
|
155
|
+
"optional",
|
|
154
156
|
"required",
|
|
155
157
|
"valid",
|
|
156
158
|
"invalid",
|
|
@@ -161,7 +163,10 @@ let variantPlugins = {
|
|
|
161
163
|
"empty",
|
|
162
164
|
// Interactive
|
|
163
165
|
"focus-within",
|
|
164
|
-
|
|
166
|
+
[
|
|
167
|
+
"hover",
|
|
168
|
+
!(0, _featureFlags).flagEnabled(config(), "hoverOnlyWhenSupported") ? "&:hover" : "@media (hover: hover) and (pointer: fine) { &:hover }",
|
|
169
|
+
],
|
|
165
170
|
"focus",
|
|
166
171
|
"focus-visible",
|
|
167
172
|
"active",
|
|
@@ -169,25 +174,25 @@ let variantPlugins = {
|
|
|
169
174
|
"disabled",
|
|
170
175
|
].map((variant)=>Array.isArray(variant) ? variant : [
|
|
171
176
|
variant,
|
|
172
|
-
|
|
177
|
+
`&:${variant}`
|
|
173
178
|
]
|
|
174
179
|
);
|
|
175
180
|
for (let [variantName, state] of pseudoVariants){
|
|
176
181
|
addVariant(variantName, (ctx)=>{
|
|
177
182
|
let result = typeof state === "function" ? state(ctx) : state;
|
|
178
|
-
return
|
|
183
|
+
return result;
|
|
179
184
|
});
|
|
180
185
|
}
|
|
181
186
|
for (let [variantName1, state1] of pseudoVariants){
|
|
182
187
|
addVariant(`group-${variantName1}`, (ctx)=>{
|
|
183
188
|
let result = typeof state1 === "function" ? state1(ctx) : state1;
|
|
184
|
-
return
|
|
189
|
+
return result.replace(/&(\S+)/, ":merge(.group)$1 &");
|
|
185
190
|
});
|
|
186
191
|
}
|
|
187
192
|
for (let [variantName2, state2] of pseudoVariants){
|
|
188
193
|
addVariant(`peer-${variantName2}`, (ctx)=>{
|
|
189
194
|
let result = typeof state2 === "function" ? state2(ctx) : state2;
|
|
190
|
-
return
|
|
195
|
+
return result.replace(/&(\S+)/, ":merge(.peer)$1 ~ &");
|
|
191
196
|
});
|
|
192
197
|
}
|
|
193
198
|
},
|
|
@@ -239,6 +244,10 @@ let variantPlugins = {
|
|
|
239
244
|
orientationVariants: ({ addVariant })=>{
|
|
240
245
|
addVariant("portrait", "@media (orientation: portrait)");
|
|
241
246
|
addVariant("landscape", "@media (orientation: landscape)");
|
|
247
|
+
},
|
|
248
|
+
prefersContrastVariants: ({ addVariant })=>{
|
|
249
|
+
addVariant("contrast-more", "@media (prefers-contrast: more)");
|
|
250
|
+
addVariant("contrast-less", "@media (prefers-contrast: less)");
|
|
242
251
|
}
|
|
243
252
|
};
|
|
244
253
|
exports.variantPlugins = variantPlugins;
|
|
@@ -3194,10 +3203,15 @@ let corePlugins = {
|
|
|
3194
3203
|
]
|
|
3195
3204
|
});
|
|
3196
3205
|
},
|
|
3197
|
-
ringWidth: ({ matchUtilities , addDefaults , addUtilities , theme })=>{
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3206
|
+
ringWidth: ({ matchUtilities , addDefaults , addUtilities , theme , config })=>{
|
|
3207
|
+
let ringColorDefault = (()=>{
|
|
3208
|
+
var ref;
|
|
3209
|
+
if ((0, _featureFlags).flagEnabled(config(), "respectDefaultRingColorOpacity")) {
|
|
3210
|
+
return theme("ringColor.DEFAULT");
|
|
3211
|
+
}
|
|
3212
|
+
let ringOpacityDefault = theme("ringOpacity.DEFAULT", "0.5");
|
|
3213
|
+
return (0, _withAlphaVariable).withAlphaValue((ref = theme("ringColor")) === null || ref === void 0 ? void 0 : ref.DEFAULT, ringOpacityDefault, `rgb(147 197 253 / ${ringOpacityDefault})`);
|
|
3214
|
+
})();
|
|
3201
3215
|
addDefaults("ring-width", {
|
|
3202
3216
|
"--tw-ring-inset": " ",
|
|
3203
3217
|
"--tw-ring-offset-width": theme("ringOffsetWidth.DEFAULT", "0px"),
|
|
@@ -3252,16 +3266,19 @@ let corePlugins = {
|
|
|
3252
3266
|
type: "color"
|
|
3253
3267
|
});
|
|
3254
3268
|
},
|
|
3255
|
-
ringOpacity: (
|
|
3256
|
-
|
|
3257
|
-
|
|
3269
|
+
ringOpacity: (helpers)=>{
|
|
3270
|
+
let { config } = helpers;
|
|
3271
|
+
return (0, _createUtilityPlugin).default("ringOpacity", [
|
|
3258
3272
|
[
|
|
3259
|
-
"
|
|
3273
|
+
"ring-opacity",
|
|
3274
|
+
[
|
|
3275
|
+
"--tw-ring-opacity"
|
|
3276
|
+
]
|
|
3260
3277
|
]
|
|
3261
|
-
]
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
}
|
|
3278
|
+
], {
|
|
3279
|
+
filterDefault: !(0, _featureFlags).flagEnabled(config(), "respectDefaultRingColorOpacity")
|
|
3280
|
+
})(helpers);
|
|
3281
|
+
},
|
|
3265
3282
|
ringOffsetWidth: (0, _createUtilityPlugin).default("ringOffsetWidth", [
|
|
3266
3283
|
[
|
|
3267
3284
|
"ring-offset",
|
package/lib/featureFlags.js
CHANGED
|
@@ -16,9 +16,13 @@ let defaults = {
|
|
|
16
16
|
optimizeUniversalDefaults: false
|
|
17
17
|
};
|
|
18
18
|
let featureFlags = {
|
|
19
|
-
future: [
|
|
19
|
+
future: [
|
|
20
|
+
"hoverOnlyWhenSupported",
|
|
21
|
+
"respectDefaultRingColorOpacity"
|
|
22
|
+
],
|
|
20
23
|
experimental: [
|
|
21
|
-
"optimizeUniversalDefaults"
|
|
24
|
+
"optimizeUniversalDefaults",
|
|
25
|
+
"matchVariant" /* , 'variantGrouping' */
|
|
22
26
|
]
|
|
23
27
|
};
|
|
24
28
|
function flagEnabled(config, flag) {
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.defaultExtractor = defaultExtractor;
|
|
6
|
+
var _featureFlagsJs = require("../featureFlags.js");
|
|
6
7
|
var regex = _interopRequireWildcard(require("./regex"));
|
|
7
8
|
function _interopRequireWildcard(obj) {
|
|
8
9
|
if (obj && obj.__esModule) {
|
|
@@ -41,6 +42,37 @@ function defaultExtractor(context) {
|
|
|
41
42
|
}
|
|
42
43
|
function* buildRegExps(context) {
|
|
43
44
|
let separator = context.tailwindConfig.separator;
|
|
45
|
+
let variantGroupingEnabled = (0, _featureFlagsJs).flagEnabled(context.tailwindConfig, "variantGrouping");
|
|
46
|
+
let utility = regex.any([
|
|
47
|
+
// Arbitrary properties
|
|
48
|
+
/\[[^\s:'"]+:[^\s\]]+\]/,
|
|
49
|
+
// Utilities
|
|
50
|
+
regex.pattern([
|
|
51
|
+
// Utility Name / Group Name
|
|
52
|
+
/-?(?:\w+)/,
|
|
53
|
+
// Normal/Arbitrary values
|
|
54
|
+
regex.optional(regex.any([
|
|
55
|
+
regex.pattern([
|
|
56
|
+
// Arbitrary values
|
|
57
|
+
/-\[[^\s:]+\]/,
|
|
58
|
+
// Not immediately followed by an `{[(`
|
|
59
|
+
/(?![{([]])/,
|
|
60
|
+
// optionally followed by an opacity modifier
|
|
61
|
+
/(?:\/[^\s'"\\$]*)?/,
|
|
62
|
+
]),
|
|
63
|
+
regex.pattern([
|
|
64
|
+
// Arbitrary values
|
|
65
|
+
/-\[[^\s]+\]/,
|
|
66
|
+
// Not immediately followed by an `{[(`
|
|
67
|
+
/(?![{([]])/,
|
|
68
|
+
// optionally followed by an opacity modifier
|
|
69
|
+
/(?:\/[^\s'"\\$]*)?/,
|
|
70
|
+
]),
|
|
71
|
+
// Normal values w/o quotes — may include an opacity modifier
|
|
72
|
+
/[-\/][^\s'"\\$={]*/,
|
|
73
|
+
])),
|
|
74
|
+
]),
|
|
75
|
+
]);
|
|
44
76
|
yield regex.pattern([
|
|
45
77
|
// Variants
|
|
46
78
|
"((?=((",
|
|
@@ -57,36 +89,20 @@ function* buildRegExps(context) {
|
|
|
57
89
|
")+))\\2)?",
|
|
58
90
|
// Important (optional)
|
|
59
91
|
/!?/,
|
|
60
|
-
regex.any([
|
|
61
|
-
//
|
|
62
|
-
/\[[^\s:'"]+:[^\s\]]+\]/,
|
|
63
|
-
// Utilities
|
|
92
|
+
variantGroupingEnabled ? regex.any([
|
|
93
|
+
// Or any of those things but grouped separated by commas
|
|
64
94
|
regex.pattern([
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
]),
|
|
77
|
-
regex.pattern([
|
|
78
|
-
// Arbitrary values
|
|
79
|
-
/-\[[^\s]+\]/,
|
|
80
|
-
// Not immediately followed by an `{[(`
|
|
81
|
-
/(?![{([]])/,
|
|
82
|
-
// optionally followed by an opacity modifier
|
|
83
|
-
/(?:\/[^\s'"\\$]*)?/,
|
|
84
|
-
]),
|
|
85
|
-
// Normal values w/o quotes — may include an opacity modifier
|
|
86
|
-
/[-\/][^\s'"\\$={]*/,
|
|
87
|
-
])),
|
|
88
|
-
]),
|
|
89
|
-
]),
|
|
95
|
+
/\(/,
|
|
96
|
+
utility,
|
|
97
|
+
regex.zeroOrMore([
|
|
98
|
+
/,/,
|
|
99
|
+
utility
|
|
100
|
+
]),
|
|
101
|
+
/\)/
|
|
102
|
+
]),
|
|
103
|
+
// Arbitrary properties, constrained utilities, arbitrary values, etc…
|
|
104
|
+
utility,
|
|
105
|
+
]) : utility,
|
|
90
106
|
]);
|
|
91
107
|
// 5. Inner matches
|
|
92
108
|
// yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
|
|
@@ -10,6 +10,7 @@ var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser")
|
|
|
10
10
|
var _normalizeScreens = require("../util/normalizeScreens");
|
|
11
11
|
var _buildMediaQuery = _interopRequireDefault(require("../util/buildMediaQuery"));
|
|
12
12
|
var _toPath = require("../util/toPath");
|
|
13
|
+
var _withAlphaVariable = require("../util/withAlphaVariable");
|
|
13
14
|
function _interopRequireDefault(obj) {
|
|
14
15
|
return obj && obj.__esModule ? obj : {
|
|
15
16
|
default: obj
|
|
@@ -40,7 +41,7 @@ function list(items) {
|
|
|
40
41
|
function listKeys(obj) {
|
|
41
42
|
return list(Object.keys(obj));
|
|
42
43
|
}
|
|
43
|
-
function validatePath(config, path, defaultValue) {
|
|
44
|
+
function validatePath(config, path, defaultValue, themeOpts = {}) {
|
|
44
45
|
const pathString = Array.isArray(path) ? pathToString(path) : path.replace(/^['"]+/g, "").replace(/['"]+$/g, "");
|
|
45
46
|
const pathSegments = Array.isArray(path) ? path : (0, _toPath).toPath(pathString);
|
|
46
47
|
const value = (0, _dlv).default(config.theme, pathSegments, defaultValue);
|
|
@@ -104,7 +105,7 @@ function validatePath(config, path, defaultValue) {
|
|
|
104
105
|
const [themeSection] = pathSegments;
|
|
105
106
|
return {
|
|
106
107
|
isValid: true,
|
|
107
|
-
value: (0, _transformThemeValue).default(themeSection)(value)
|
|
108
|
+
value: (0, _transformThemeValue).default(themeSection)(value, themeOpts)
|
|
108
109
|
};
|
|
109
110
|
}
|
|
110
111
|
function extractArgs(node, vNodes, functions) {
|
|
@@ -142,10 +143,21 @@ let nodeTypePropertyMap = {
|
|
|
142
143
|
function _default({ tailwindConfig: config }) {
|
|
143
144
|
let functions = {
|
|
144
145
|
theme: (node, path, ...defaultValue)=>{
|
|
145
|
-
|
|
146
|
+
let matches = path.match(/^([^\/\s]+)(?:\s*\/\s*([^\/\s]+))$/);
|
|
147
|
+
let alpha = undefined;
|
|
148
|
+
if (matches) {
|
|
149
|
+
path = matches[1];
|
|
150
|
+
alpha = matches[2];
|
|
151
|
+
}
|
|
152
|
+
let { isValid , value , error } = validatePath(config, path, defaultValue.length ? defaultValue : undefined, {
|
|
153
|
+
opacityValue: alpha
|
|
154
|
+
});
|
|
146
155
|
if (!isValid) {
|
|
147
156
|
throw node.error(error);
|
|
148
157
|
}
|
|
158
|
+
if (alpha !== undefined) {
|
|
159
|
+
value = (0, _withAlphaVariable).withAlphaValue(value, alpha, value);
|
|
160
|
+
}
|
|
149
161
|
return value;
|
|
150
162
|
},
|
|
151
163
|
screen: (node, screen)=>{
|
package/lib/lib/generateRules.js
CHANGED
|
@@ -17,6 +17,7 @@ var _dataTypes = require("../util/dataTypes");
|
|
|
17
17
|
var _setupContextUtils = require("./setupContextUtils");
|
|
18
18
|
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
19
19
|
var _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
|
|
20
|
+
var _featureFlags = require("../featureFlags");
|
|
20
21
|
function _interopRequireDefault(obj) {
|
|
21
22
|
return obj && obj.__esModule ? obj : {
|
|
22
23
|
default: obj
|
|
@@ -176,7 +177,7 @@ function applyVariant(variant, matches, context) {
|
|
|
176
177
|
context.variantOrder.set(variant, sort);
|
|
177
178
|
}
|
|
178
179
|
if (context.variantMap.has(variant)) {
|
|
179
|
-
let variantFunctionTuples = context.variantMap.get(variant);
|
|
180
|
+
let variantFunctionTuples = context.variantMap.get(variant).slice();
|
|
180
181
|
let result = [];
|
|
181
182
|
for (let [meta, rule1] of matches){
|
|
182
183
|
// Don't generate variants for user css
|
|
@@ -234,6 +235,25 @@ function applyVariant(variant, matches, context) {
|
|
|
234
235
|
},
|
|
235
236
|
args
|
|
236
237
|
});
|
|
238
|
+
// It can happen that a list of format strings is returned from within the function. In that
|
|
239
|
+
// case, we have to process them as well. We can use the existing `variantSort`.
|
|
240
|
+
if (Array.isArray(ruleWithVariant)) {
|
|
241
|
+
for (let [idx, variantFunction] of ruleWithVariant.entries()){
|
|
242
|
+
// This is a little bit scary since we are pushing to an array of items that we are
|
|
243
|
+
// currently looping over. However, you can also think of it like a processing queue
|
|
244
|
+
// where you keep handling jobs until everything is done and each job can queue more
|
|
245
|
+
// jobs if needed.
|
|
246
|
+
variantFunctionTuples.push([
|
|
247
|
+
// TODO: This could have potential bugs if we shift the sort order from variant A far
|
|
248
|
+
// enough into the sort space of variant B. The chances are low, but if this happens
|
|
249
|
+
// then this might be the place too look at. One potential solution to this problem is
|
|
250
|
+
// reserving additional X places for these 'unknown' variants in between.
|
|
251
|
+
variantSort | BigInt(idx << ruleWithVariant.length),
|
|
252
|
+
variantFunction,
|
|
253
|
+
]);
|
|
254
|
+
}
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
237
257
|
if (typeof ruleWithVariant === "string") {
|
|
238
258
|
collectedFormats.push(ruleWithVariant);
|
|
239
259
|
}
|
|
@@ -452,7 +472,7 @@ function* recordCandidates(matches, classCandidate) {
|
|
|
452
472
|
yield match;
|
|
453
473
|
}
|
|
454
474
|
}
|
|
455
|
-
function* resolveMatches(candidate, context) {
|
|
475
|
+
function* resolveMatches(candidate, context, original = candidate) {
|
|
456
476
|
let separator = context.tailwindConfig.separator;
|
|
457
477
|
let [classCandidate, ...variants] = splitWithSeparator(candidate, separator).reverse();
|
|
458
478
|
let important = false;
|
|
@@ -460,6 +480,14 @@ function* resolveMatches(candidate, context) {
|
|
|
460
480
|
important = true;
|
|
461
481
|
classCandidate = classCandidate.slice(1);
|
|
462
482
|
}
|
|
483
|
+
if ((0, _featureFlags).flagEnabled(context.tailwindConfig, "variantGrouping")) {
|
|
484
|
+
if (classCandidate.startsWith("(") && classCandidate.endsWith(")")) {
|
|
485
|
+
let base = variants.slice().reverse().join(separator);
|
|
486
|
+
for (let part of (0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(classCandidate.slice(1, -1), ",")){
|
|
487
|
+
yield* resolveMatches(base + separator + part, context, original);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
463
491
|
// TODO: Reintroduce this in ways that doesn't break on false positives
|
|
464
492
|
// function sortAgainst(toSort, against) {
|
|
465
493
|
// return toSort.slice().sort((a, z) => {
|
|
@@ -589,10 +617,13 @@ function* resolveMatches(candidate, context) {
|
|
|
589
617
|
]
|
|
590
618
|
});
|
|
591
619
|
container.walkRules((rule)=>{
|
|
620
|
+
var ref;
|
|
592
621
|
if (inKeyframes(rule)) return;
|
|
622
|
+
var ref2;
|
|
593
623
|
rule.selector = (0, _formatVariantSelector).finalizeSelector(finalFormat, {
|
|
594
624
|
selector: rule.selector,
|
|
595
|
-
candidate,
|
|
625
|
+
candidate: original,
|
|
626
|
+
base: candidate.split(new RegExp(`\\${(ref2 = context === null || context === void 0 ? void 0 : (ref = context.tailwindConfig) === null || ref === void 0 ? void 0 : ref.separator) !== null && ref2 !== void 0 ? ref2 : ":"}(?![^[]*\\])`)).pop(),
|
|
596
627
|
context
|
|
597
628
|
});
|
|
598
629
|
});
|
|
@@ -12,6 +12,7 @@ var _url = _interopRequireDefault(require("url"));
|
|
|
12
12
|
var _postcss = _interopRequireDefault(require("postcss"));
|
|
13
13
|
var _dlv = _interopRequireDefault(require("dlv"));
|
|
14
14
|
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
15
|
+
var _featureFlagsJs = require("../featureFlags.js");
|
|
15
16
|
var _transformThemeValue = _interopRequireDefault(require("../util/transformThemeValue"));
|
|
16
17
|
var _parseObjectStyles = _interopRequireDefault(require("../util/parseObjectStyles"));
|
|
17
18
|
var _prefixSelector = _interopRequireDefault(require("../util/prefixSelector"));
|
|
@@ -225,48 +226,27 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
225
226
|
}
|
|
226
227
|
return context.tailwindConfig.prefix + identifier;
|
|
227
228
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
245
|
-
}
|
|
246
|
-
return result;
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
if (!isValidVariantFormatString(variantFunction)) {
|
|
250
|
-
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
251
|
-
}
|
|
252
|
-
return parseVariant(variantFunction);
|
|
253
|
-
});
|
|
254
|
-
insertInto(variantList, variantName, options);
|
|
255
|
-
variantMap.set(variantName, variantFunctions);
|
|
256
|
-
},
|
|
229
|
+
function resolveThemeValue(path, defaultValue, opts = {}) {
|
|
230
|
+
const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
|
|
231
|
+
const value = getConfigValue([
|
|
232
|
+
"theme",
|
|
233
|
+
pathRoot,
|
|
234
|
+
...subPaths
|
|
235
|
+
], defaultValue);
|
|
236
|
+
return (0, _transformThemeValue).default(pathRoot)(value, opts);
|
|
237
|
+
}
|
|
238
|
+
const theme = Object.assign((path, defaultValue = undefined)=>resolveThemeValue(path, defaultValue)
|
|
239
|
+
, {
|
|
240
|
+
withAlpha: (path, opacityValue)=>resolveThemeValue(path, undefined, {
|
|
241
|
+
opacityValue
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
let api1 = {
|
|
257
245
|
postcss: _postcss.default,
|
|
258
246
|
prefix: applyConfiguredPrefix,
|
|
259
247
|
e: _escapeClassName.default,
|
|
260
248
|
config: getConfigValue,
|
|
261
|
-
theme
|
|
262
|
-
const [pathRoot, ...subPaths] = (0, _toPath).toPath(path);
|
|
263
|
-
const value = getConfigValue([
|
|
264
|
-
"theme",
|
|
265
|
-
pathRoot,
|
|
266
|
-
...subPaths
|
|
267
|
-
], defaultValue);
|
|
268
|
-
return (0, _transformThemeValue).default(pathRoot)(value);
|
|
269
|
-
},
|
|
249
|
+
theme,
|
|
270
250
|
corePlugins: (path)=>{
|
|
271
251
|
if (Array.isArray(tailwindConfig.corePlugins)) {
|
|
272
252
|
return tailwindConfig.corePlugins.includes(path);
|
|
@@ -468,30 +448,56 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
468
448
|
context.candidateRuleMap.get(prefixedIdentifier).push(withOffsets);
|
|
469
449
|
}
|
|
470
450
|
},
|
|
471
|
-
|
|
451
|
+
addVariant (variantName, variantFunctions, options = {}) {
|
|
452
|
+
variantFunctions = [].concat(variantFunctions).map((variantFunction)=>{
|
|
453
|
+
if (typeof variantFunction !== "string") {
|
|
454
|
+
// Safelist public API functions
|
|
455
|
+
return (api)=>{
|
|
456
|
+
let { args , modifySelectors , container , separator , wrap , format } = api;
|
|
457
|
+
let result = variantFunction(Object.assign({
|
|
458
|
+
modifySelectors,
|
|
459
|
+
container,
|
|
460
|
+
separator
|
|
461
|
+
}, variantFunction[MATCH_VARIANT] && {
|
|
462
|
+
args,
|
|
463
|
+
wrap,
|
|
464
|
+
format
|
|
465
|
+
}));
|
|
466
|
+
if (typeof result === "string" && !isValidVariantFormatString(result)) {
|
|
467
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
468
|
+
}
|
|
469
|
+
if (Array.isArray(result)) {
|
|
470
|
+
return result.map((variant)=>parseVariant(variant)
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
// result may be undefined with legacy variants that use APIs like `modifySelectors`
|
|
474
|
+
return result && parseVariant(result)(api);
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
478
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
479
|
+
}
|
|
480
|
+
return parseVariant(variantFunction);
|
|
481
|
+
});
|
|
482
|
+
insertInto(variantList, variantName, options);
|
|
483
|
+
variantMap.set(variantName, variantFunctions);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
if ((0, _featureFlagsJs).flagEnabled(tailwindConfig, "matchVariant")) {
|
|
487
|
+
api1.matchVariant = function(variants, options) {
|
|
472
488
|
for(let variant in variants){
|
|
473
489
|
var ref;
|
|
474
490
|
for (let [k, v] of Object.entries((ref = options === null || options === void 0 ? void 0 : options.values) !== null && ref !== void 0 ? ref : {})){
|
|
475
|
-
|
|
491
|
+
api1.addVariant(`${variant}-${k}`, variants[variant](v));
|
|
476
492
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
if (!formatString) return null;
|
|
480
|
-
if (!formatString.startsWith("@")) {
|
|
481
|
-
return formatString;
|
|
482
|
-
}
|
|
483
|
-
let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(formatString);
|
|
484
|
-
return wrap(_postcss.default.atRule({
|
|
485
|
-
name,
|
|
486
|
-
params: params.trim()
|
|
487
|
-
}));
|
|
488
|
-
}, {
|
|
493
|
+
api1.addVariant(variant, Object.assign(({ args })=>variants[variant](args)
|
|
494
|
+
, {
|
|
489
495
|
[MATCH_VARIANT]: true
|
|
490
496
|
}), options);
|
|
491
497
|
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
return
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
return api1;
|
|
495
501
|
}
|
|
496
502
|
let fileModifiedMapCache = new WeakMap();
|
|
497
503
|
function getFileModifiedMap(context) {
|
|
@@ -604,6 +610,7 @@ function resolvePlugins(context, root) {
|
|
|
604
610
|
let afterVariants = [
|
|
605
611
|
_corePlugins.variantPlugins["directionVariants"],
|
|
606
612
|
_corePlugins.variantPlugins["reducedMotionVariants"],
|
|
613
|
+
_corePlugins.variantPlugins["prefersContrastVariants"],
|
|
607
614
|
_corePlugins.variantPlugins["darkVariants"],
|
|
608
615
|
_corePlugins.variantPlugins["printVariant"],
|
|
609
616
|
_corePlugins.variantPlugins["screenVariants"],
|