tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7fa2a20
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 +9 -0
- package/lib/cli-peer-dependencies.js +4 -3
- package/lib/cli.js +11 -2
- package/lib/corePlugins.js +6 -0
- package/lib/lib/defaultExtractor.js +159 -32
- package/lib/lib/expandApplyAtRules.js +21 -3
- package/lib/lib/expandTailwindAtRules.js +4 -4
- package/lib/lib/generateRules.js +19 -1
- package/lib/lib/regex.js +53 -0
- package/lib/lib/setupContextUtils.js +34 -19
- package/lib/util/formatVariantSelector.js +54 -44
- package/lib/util/parseBoxShadowValue.js +2 -43
- package/lib/util/splitAtTopLevelOnly.js +72 -0
- package/package.json +5 -5
- package/peers/index.js +38 -37
- package/src/cli-peer-dependencies.js +3 -1
- package/src/cli.js +12 -1
- package/src/corePlugins.js +2 -0
- package/src/lib/defaultExtractor.js +162 -35
- package/src/lib/expandApplyAtRules.js +32 -4
- package/src/lib/expandTailwindAtRules.js +4 -4
- package/src/lib/generateRules.js +18 -1
- package/src/lib/regex.js +74 -0
- package/src/lib/setupContextUtils.js +42 -20
- package/src/util/formatVariantSelector.js +61 -50
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/splitAtTopLevelOnly.js +71 -0
package/CHANGELOG.md
CHANGED
|
@@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
19
19
|
- Support PostCSS config options in config file in CLI ([#8226](https://github.com/tailwindlabs/tailwindcss/pull/8226))
|
|
20
20
|
- Remove default `[hidden]` style in preflight ([#8248](https://github.com/tailwindlabs/tailwindcss/pull/8248))
|
|
21
21
|
- Only check selectors containing base apply candidates for circular dependencies ([#8222](https://github.com/tailwindlabs/tailwindcss/pull/8222))
|
|
22
|
+
- Rewrite default class extractor ([#8204](https://github.com/tailwindlabs/tailwindcss/pull/8204))
|
|
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
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Try using local `postcss` installation first in the CLI ([#8270](https://github.com/tailwindlabs/tailwindcss/pull/8270))
|
|
22
28
|
|
|
23
29
|
### Added
|
|
24
30
|
|
|
@@ -32,6 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
32
38
|
- Add `enabled` variant ([#7905](https://github.com/tailwindlabs/tailwindcss/pull/7905))
|
|
33
39
|
- Add TypeScript types for the `tailwind.config.js` file ([#7891](https://github.com/tailwindlabs/tailwindcss/pull/7891))
|
|
34
40
|
- Add `backdrop` variant ([#7924](https://github.com/tailwindlabs/tailwindcss/pull/7924))
|
|
41
|
+
- Add `grid-flow-dense` utility ([#8193](https://github.com/tailwindlabs/tailwindcss/pull/8193))
|
|
42
|
+
- Add `mix-blend-plus-lighter` utility ([#8288](https://github.com/tailwindlabs/tailwindcss/pull/8288))
|
|
43
|
+
- Add arbitrary variants ([#8299](https://github.com/tailwindlabs/tailwindcss/pull/8299))
|
|
35
44
|
|
|
36
45
|
## [3.0.24] - 2022-04-12
|
|
37
46
|
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
exports.lazyPostcss = lazyPostcss;
|
|
5
6
|
exports.lazyAutoprefixer = lazyAutoprefixer;
|
|
6
7
|
exports.lazyCssnano = lazyCssnano;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
function lazyPostcss() {
|
|
9
|
+
return require("postcss");
|
|
10
|
+
}
|
|
10
11
|
function lazyAutoprefixer() {
|
|
11
12
|
return require("autoprefixer");
|
|
12
13
|
}
|
package/lib/cli.js
CHANGED
|
@@ -130,6 +130,13 @@ function oneOf(...options) {
|
|
|
130
130
|
manualParsing: true
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
+
function loadPostcss() {
|
|
134
|
+
// Try to load a local `postcss` version first
|
|
135
|
+
try {
|
|
136
|
+
return require("postcss");
|
|
137
|
+
} catch {}
|
|
138
|
+
return (0, _indexJs).lazyPostcss();
|
|
139
|
+
}
|
|
133
140
|
let commands = {
|
|
134
141
|
init: {
|
|
135
142
|
run: init,
|
|
@@ -528,7 +535,8 @@ async function build() {
|
|
|
528
535
|
return (0, _indexJs).lazyCssnano()(options);
|
|
529
536
|
})(),
|
|
530
537
|
].filter(Boolean);
|
|
531
|
-
let
|
|
538
|
+
let postcss = loadPostcss();
|
|
539
|
+
let processor = postcss(plugins);
|
|
532
540
|
function processCSS(css) {
|
|
533
541
|
let start = process.hrtime.bigint();
|
|
534
542
|
return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
|
|
@@ -649,7 +657,8 @@ async function build() {
|
|
|
649
657
|
let tailwindPluginIdx = plugins.indexOf("__TAILWIND_PLUGIN_POSITION__");
|
|
650
658
|
let copy = plugins.slice();
|
|
651
659
|
copy.splice(tailwindPluginIdx, 1, tailwindPlugin);
|
|
652
|
-
let
|
|
660
|
+
let postcss = loadPostcss();
|
|
661
|
+
let processor = postcss(copy);
|
|
653
662
|
function processCSS(css) {
|
|
654
663
|
let start = process.hrtime.bigint();
|
|
655
664
|
return Promise.resolve().then(()=>output ? _fs.default.promises.mkdir(_path.default.dirname(output), {
|
package/lib/corePlugins.js
CHANGED
|
@@ -1420,6 +1420,9 @@ let corePlugins = {
|
|
|
1420
1420
|
".grid-flow-col": {
|
|
1421
1421
|
gridAutoFlow: "column"
|
|
1422
1422
|
},
|
|
1423
|
+
".grid-flow-dense": {
|
|
1424
|
+
gridAutoFlow: "dense"
|
|
1425
|
+
},
|
|
1423
1426
|
".grid-flow-row-dense": {
|
|
1424
1427
|
gridAutoFlow: "row dense"
|
|
1425
1428
|
},
|
|
@@ -3065,6 +3068,9 @@ let corePlugins = {
|
|
|
3065
3068
|
},
|
|
3066
3069
|
".mix-blend-luminosity": {
|
|
3067
3070
|
"mix-blend-mode": "luminosity"
|
|
3071
|
+
},
|
|
3072
|
+
".mix-blend-plus-lighter": {
|
|
3073
|
+
"mix-blend-mode": "plus-lighter"
|
|
3068
3074
|
}
|
|
3069
3075
|
});
|
|
3070
3076
|
},
|
|
@@ -3,38 +3,165 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports.defaultExtractor = defaultExtractor;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
var regex = _interopRequireWildcard(require("./regex"));
|
|
7
|
+
function _interopRequireWildcard(obj) {
|
|
8
|
+
if (obj && obj.__esModule) {
|
|
9
|
+
return obj;
|
|
10
|
+
} else {
|
|
11
|
+
var newObj = {};
|
|
12
|
+
if (obj != null) {
|
|
13
|
+
for(var key in obj){
|
|
14
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
15
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
16
|
+
if (desc.get || desc.set) {
|
|
17
|
+
Object.defineProperty(newObj, key, desc);
|
|
18
|
+
} else {
|
|
19
|
+
newObj[key] = obj[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
newObj.default = obj;
|
|
25
|
+
return newObj;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function defaultExtractor(context) {
|
|
29
|
+
let patterns = Array.from(buildRegExps(context));
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} content
|
|
32
|
+
*/ return (content)=>{
|
|
33
|
+
/** @type {(string|string)[]} */ let results = [];
|
|
34
|
+
for (let pattern of patterns){
|
|
35
|
+
var ref;
|
|
36
|
+
results.push(...(ref = content.match(pattern)) !== null && ref !== void 0 ? ref : []);
|
|
37
|
+
}
|
|
38
|
+
return results.filter((v)=>v !== undefined
|
|
39
|
+
).map(clipAtBalancedParens);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function* buildRegExps(context) {
|
|
43
|
+
let separator = context.tailwindConfig.separator;
|
|
44
|
+
yield regex.pattern([
|
|
45
|
+
// Variants
|
|
46
|
+
"((?=((",
|
|
47
|
+
regex.any([
|
|
48
|
+
regex.pattern([
|
|
49
|
+
/\[[^\s"'\\]+\]/,
|
|
50
|
+
separator
|
|
51
|
+
]),
|
|
52
|
+
regex.pattern([
|
|
53
|
+
/[^\s"'\[\\]+/,
|
|
54
|
+
separator
|
|
55
|
+
])
|
|
56
|
+
], true),
|
|
57
|
+
")+))\\2)?",
|
|
58
|
+
// Important (optional)
|
|
59
|
+
/!?/,
|
|
60
|
+
regex.any([
|
|
61
|
+
// Arbitrary properties
|
|
62
|
+
/\[[^\s:'"]+:[^\s\]]+\]/,
|
|
63
|
+
// Utilities
|
|
64
|
+
regex.pattern([
|
|
65
|
+
// Utility Name / Group Name
|
|
66
|
+
/-?(?:\w+)/,
|
|
67
|
+
// Normal/Arbitrary values
|
|
68
|
+
regex.optional(regex.any([
|
|
69
|
+
regex.pattern([
|
|
70
|
+
// Arbitrary values
|
|
71
|
+
/-\[[^\s:]+\]/,
|
|
72
|
+
// Not immediately followed by an `{[(`
|
|
73
|
+
/(?![{([]])/,
|
|
74
|
+
// optionally followed by an opacity modifier
|
|
75
|
+
/(?:\/[^\s'"\\$]*)?/,
|
|
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
|
+
]),
|
|
90
|
+
]);
|
|
91
|
+
// 5. Inner matches
|
|
92
|
+
// yield /[^<>"'`\s.(){}[\]#=%$]*[^<>"'`\s.(){}[\]#=%:$]/g
|
|
93
|
+
}
|
|
94
|
+
// We want to capture any "special" characters
|
|
95
|
+
// AND the characters immediately following them (if there is one)
|
|
96
|
+
let SPECIALS = /([\[\]'"`])([^\[\]'"`])?/g;
|
|
97
|
+
let ALLOWED_CLASS_CHARACTERS = /[^"'`\s<>\]]+/;
|
|
98
|
+
/**
|
|
99
|
+
* Clips a string ensuring that parentheses, quotes, etc… are balanced
|
|
100
|
+
* Used for arbitrary values only
|
|
101
|
+
*
|
|
102
|
+
* We will go past the end of the balanced parens until we find a non-class character
|
|
103
|
+
*
|
|
104
|
+
* Depth matching behavior:
|
|
105
|
+
* w-[calc(100%-theme('spacing[some_key][1.5]'))]']
|
|
106
|
+
* ┬ ┬ ┬┬ ┬ ┬┬ ┬┬┬┬┬┬┬
|
|
107
|
+
* 1 2 3 4 34 3 210 END
|
|
108
|
+
* ╰────┴──────────┴────────┴────────┴┴───┴─┴┴┴
|
|
109
|
+
*
|
|
110
|
+
* @param {string} input
|
|
111
|
+
*/ function clipAtBalancedParens(input) {
|
|
112
|
+
// We are care about this for arbitrary values
|
|
113
|
+
if (!input.includes("-[")) {
|
|
114
|
+
return input;
|
|
115
|
+
}
|
|
116
|
+
let depth = 0;
|
|
117
|
+
let openStringTypes = [];
|
|
118
|
+
// Find all parens, brackets, quotes, etc
|
|
119
|
+
// Stop when we end at a balanced pair
|
|
120
|
+
// This is naive and will treat mismatched parens as balanced
|
|
121
|
+
// This shouldn't be a problem in practice though
|
|
122
|
+
let matches = input.matchAll(SPECIALS);
|
|
123
|
+
// We can't use lookbehind assertions because we have to support Safari
|
|
124
|
+
// So, instead, we've emulated it using capture groups and we'll re-work the matches to accommodate
|
|
125
|
+
matches = Array.from(matches).flatMap((match)=>{
|
|
126
|
+
const [, ...groups] = match;
|
|
127
|
+
return groups.map((group, idx)=>Object.assign([], match, {
|
|
128
|
+
index: match.index + idx,
|
|
129
|
+
0: group
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
for (let match1 of matches){
|
|
134
|
+
let char = match1[0];
|
|
135
|
+
let inStringType = openStringTypes[openStringTypes.length - 1];
|
|
136
|
+
if (char === inStringType) {
|
|
137
|
+
openStringTypes.pop();
|
|
138
|
+
} else if (char === "'" || char === '"' || char === "`") {
|
|
139
|
+
openStringTypes.push(char);
|
|
140
|
+
}
|
|
141
|
+
if (inStringType) {
|
|
142
|
+
continue;
|
|
143
|
+
} else if (char === "[") {
|
|
144
|
+
depth++;
|
|
145
|
+
continue;
|
|
146
|
+
} else if (char === "]") {
|
|
147
|
+
depth--;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
// We've gone one character past the point where we should stop
|
|
151
|
+
// This means that there was an extra closing `]`
|
|
152
|
+
// We'll clip to just before it
|
|
153
|
+
if (depth < 0) {
|
|
154
|
+
return input.substring(0, match1.index);
|
|
155
|
+
}
|
|
156
|
+
// We've finished balancing the brackets but there still may be characters that can be included
|
|
157
|
+
// For example in the class `text-[#336699]/[.35]`
|
|
158
|
+
// The depth goes to `0` at the closing `]` but goes up again at the `[`
|
|
159
|
+
// If we're at zero and encounter a non-class character then we clip the class there
|
|
160
|
+
if (depth === 0 && !ALLOWED_CLASS_CHARACTERS.test(char)) {
|
|
161
|
+
return input.substring(0, match1.index);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return input;
|
|
38
165
|
} // Regular utilities
|
|
39
166
|
// {{modifier}:}*{namespace}{-{suffix}}*{/{opacityModifier}}?
|
|
40
167
|
// Arbitrary values
|
|
@@ -47,6 +47,14 @@ function _interopRequireDefault(obj) {
|
|
|
47
47
|
groups: normalizedGroups
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
+
let selectorExtractor = (0, _postcssSelectorParser).default((root)=>root.nodes.map((node)=>node.toString()
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
/**
|
|
54
|
+
* @param {string} ruleSelectors
|
|
55
|
+
*/ function extractSelectors(ruleSelectors) {
|
|
56
|
+
return selectorExtractor.transformSync(ruleSelectors);
|
|
57
|
+
}
|
|
50
58
|
function extractBaseCandidates(candidates, separator) {
|
|
51
59
|
let baseClasses = new Set();
|
|
52
60
|
for (let candidate of candidates){
|
|
@@ -281,8 +289,8 @@ function processApply(root, context, localCache) {
|
|
|
281
289
|
needle1.replace(/\\2c /g, "\\,")
|
|
282
290
|
])
|
|
283
291
|
];
|
|
284
|
-
let utilitySelectorsList = utilitySelectors
|
|
285
|
-
return selector
|
|
292
|
+
let utilitySelectorsList = extractSelectors(utilitySelectors);
|
|
293
|
+
return extractSelectors(selector).map((s)=>{
|
|
286
294
|
let replaced = [];
|
|
287
295
|
for (let utilitySelector of utilitySelectorsList){
|
|
288
296
|
let replacedSelector = utilitySelector;
|
|
@@ -429,7 +437,17 @@ function processApply(root, context, localCache) {
|
|
|
429
437
|
rule.remove();
|
|
430
438
|
return;
|
|
431
439
|
}
|
|
432
|
-
|
|
440
|
+
// Strip the important selector from the parent selector if at the beginning
|
|
441
|
+
let importantSelector = typeof context.tailwindConfig.important === "string" ? context.tailwindConfig.important : null;
|
|
442
|
+
// We only want to move the "important" selector if this is a Tailwind-generated utility
|
|
443
|
+
// We do *not* want to do this for user CSS that happens to be structured the same
|
|
444
|
+
let isGenerated = parent.raws.tailwind !== undefined;
|
|
445
|
+
let parentSelector = isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0 ? parent.selector.slice(importantSelector.length) : parent.selector;
|
|
446
|
+
rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate);
|
|
447
|
+
// And then re-add it if it was removed
|
|
448
|
+
if (importantSelector && parentSelector !== parent.selector) {
|
|
449
|
+
rule.selector = `${importantSelector} ${rule.selector}`;
|
|
450
|
+
}
|
|
433
451
|
rule.walkDecls((d)=>{
|
|
434
452
|
d.important = meta.important || important;
|
|
435
453
|
});
|
|
@@ -42,7 +42,7 @@ function expandTailwindAtRules(context) {
|
|
|
42
42
|
env.DEBUG && console.time("Reading changed files");
|
|
43
43
|
for (let { content , extension } of context.changedContent){
|
|
44
44
|
let transformer = getTransformer(context.tailwindConfig, extension);
|
|
45
|
-
let extractor = getExtractor(context
|
|
45
|
+
let extractor = getExtractor(context, extension);
|
|
46
46
|
getClassCandidates(transformer(content), extractor, candidates, seen);
|
|
47
47
|
}
|
|
48
48
|
env.DEBUG && console.timeEnd("Reading changed files");
|
|
@@ -174,9 +174,9 @@ const builtInTransformers = {
|
|
|
174
174
|
,
|
|
175
175
|
svelte: (content)=>content.replace(/(?:^|\s)class:/g, " ")
|
|
176
176
|
};
|
|
177
|
-
function getExtractor(
|
|
178
|
-
let extractors = tailwindConfig.content.extract;
|
|
179
|
-
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT;
|
|
177
|
+
function getExtractor(context, fileExtension) {
|
|
178
|
+
let extractors = context.tailwindConfig.content.extract;
|
|
179
|
+
return extractors[fileExtension] || extractors.DEFAULT || builtInExtractors[fileExtension] || builtInExtractors.DEFAULT(context);
|
|
180
180
|
}
|
|
181
181
|
function getTransformer(tailwindConfig, fileExtension) {
|
|
182
182
|
let transformers = tailwindConfig.content.transform;
|
package/lib/lib/generateRules.js
CHANGED
|
@@ -14,7 +14,9 @@ var sharedState = _interopRequireWildcard(require("./sharedState"));
|
|
|
14
14
|
var _formatVariantSelector = require("../util/formatVariantSelector");
|
|
15
15
|
var _nameClass = require("../util/nameClass");
|
|
16
16
|
var _dataTypes = require("../util/dataTypes");
|
|
17
|
+
var _setupContextUtils = require("./setupContextUtils");
|
|
17
18
|
var _isValidArbitraryValue = _interopRequireDefault(require("../util/isValidArbitraryValue"));
|
|
19
|
+
var _splitAtTopLevelOnlyJs = require("../util/splitAtTopLevelOnly.js");
|
|
18
20
|
function _interopRequireDefault(obj) {
|
|
19
21
|
return obj && obj.__esModule ? obj : {
|
|
20
22
|
default: obj
|
|
@@ -151,6 +153,22 @@ function applyVariant(variant, matches, context) {
|
|
|
151
153
|
if (matches.length === 0) {
|
|
152
154
|
return matches;
|
|
153
155
|
}
|
|
156
|
+
// Register arbitrary variants
|
|
157
|
+
if (isArbitraryValue(variant) && !context.variantMap.has(variant)) {
|
|
158
|
+
let selector = (0, _dataTypes).normalize(variant.slice(1, -1));
|
|
159
|
+
if (!(0, _setupContextUtils).isValidVariantFormatString(selector)) {
|
|
160
|
+
return [];
|
|
161
|
+
}
|
|
162
|
+
let fn = (0, _setupContextUtils).parseVariant(selector);
|
|
163
|
+
let sort = Array.from(context.variantOrder.values()).pop() << 1n;
|
|
164
|
+
context.variantMap.set(variant, [
|
|
165
|
+
[
|
|
166
|
+
sort,
|
|
167
|
+
fn
|
|
168
|
+
]
|
|
169
|
+
]);
|
|
170
|
+
context.variantOrder.set(variant, sort);
|
|
171
|
+
}
|
|
154
172
|
if (context.variantMap.has(variant)) {
|
|
155
173
|
let variantFunctionTuples = context.variantMap.get(variant);
|
|
156
174
|
let result = [];
|
|
@@ -416,7 +434,7 @@ function splitWithSeparator(input, separator) {
|
|
|
416
434
|
sharedState.NOT_ON_DEMAND
|
|
417
435
|
];
|
|
418
436
|
}
|
|
419
|
-
return
|
|
437
|
+
return Array.from((0, _splitAtTopLevelOnlyJs).splitAtTopLevelOnly(input, separator));
|
|
420
438
|
}
|
|
421
439
|
function* recordCandidates(matches, classCandidate) {
|
|
422
440
|
for (const match of matches){
|
package/lib/lib/regex.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.pattern = pattern;
|
|
6
|
+
exports.withoutCapturing = withoutCapturing;
|
|
7
|
+
exports.any = any;
|
|
8
|
+
exports.optional = optional;
|
|
9
|
+
exports.zeroOrMore = zeroOrMore;
|
|
10
|
+
exports.nestedBrackets = nestedBrackets;
|
|
11
|
+
exports.escape = escape;
|
|
12
|
+
const REGEX_SPECIAL = /[\\^$.*+?()[\]{}|]/g;
|
|
13
|
+
const REGEX_HAS_SPECIAL = RegExp(REGEX_SPECIAL.source);
|
|
14
|
+
/**
|
|
15
|
+
* @param {string|RegExp|Array<string|RegExp>} source
|
|
16
|
+
*/ function toSource(source) {
|
|
17
|
+
source = Array.isArray(source) ? source : [
|
|
18
|
+
source
|
|
19
|
+
];
|
|
20
|
+
source = source.map((item)=>item instanceof RegExp ? item.source : item
|
|
21
|
+
);
|
|
22
|
+
return source.join("");
|
|
23
|
+
}
|
|
24
|
+
function pattern(source) {
|
|
25
|
+
return new RegExp(toSource(source), "g");
|
|
26
|
+
}
|
|
27
|
+
function withoutCapturing(source) {
|
|
28
|
+
return new RegExp(`(?:${toSource(source)})`, "g");
|
|
29
|
+
}
|
|
30
|
+
function any(sources) {
|
|
31
|
+
return `(?:${sources.map(toSource).join("|")})`;
|
|
32
|
+
}
|
|
33
|
+
function optional(source) {
|
|
34
|
+
return `(?:${toSource(source)})?`;
|
|
35
|
+
}
|
|
36
|
+
function zeroOrMore(source) {
|
|
37
|
+
return `(?:${toSource(source)})*`;
|
|
38
|
+
}
|
|
39
|
+
function nestedBrackets(open, close, depth = 1) {
|
|
40
|
+
return withoutCapturing([
|
|
41
|
+
escape(open),
|
|
42
|
+
/[^\s]*/,
|
|
43
|
+
depth === 1 ? `[^${escape(open)}${escape(close)}\s]*` : any([
|
|
44
|
+
`[^${escape(open)}${escape(close)}\s]*`,
|
|
45
|
+
nestedBrackets(open, close, depth - 1)
|
|
46
|
+
]),
|
|
47
|
+
/[^\s]*/,
|
|
48
|
+
escape(close),
|
|
49
|
+
]);
|
|
50
|
+
}
|
|
51
|
+
function escape(string) {
|
|
52
|
+
return string && REGEX_HAS_SPECIAL.test(string) ? string.replace(REGEX_SPECIAL, "\\$&") : string || "";
|
|
53
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
exports.isValidVariantFormatString = isValidVariantFormatString;
|
|
6
|
+
exports.parseVariant = parseVariant;
|
|
5
7
|
exports.getFileModifiedMap = getFileModifiedMap;
|
|
6
8
|
exports.createContext = createContext;
|
|
7
9
|
exports.getContext = getContext;
|
|
@@ -183,6 +185,29 @@ function withIdentifiers(styles) {
|
|
|
183
185
|
});
|
|
184
186
|
});
|
|
185
187
|
}
|
|
188
|
+
function isValidVariantFormatString(format) {
|
|
189
|
+
return format.startsWith("@") || format.includes("&");
|
|
190
|
+
}
|
|
191
|
+
function parseVariant(variant) {
|
|
192
|
+
variant = variant.replace(/\n+/g, "").replace(/\s{1,}/g, " ").trim();
|
|
193
|
+
let fns = parseVariantFormatString(variant).map((str)=>{
|
|
194
|
+
if (!str.startsWith("@")) {
|
|
195
|
+
return ({ format })=>format(str)
|
|
196
|
+
;
|
|
197
|
+
}
|
|
198
|
+
let [, name, params] = /@(.*?)( .+|[({].*)/g.exec(str);
|
|
199
|
+
return ({ wrap })=>wrap(_postcss.default.atRule({
|
|
200
|
+
name,
|
|
201
|
+
params: params.trim()
|
|
202
|
+
}))
|
|
203
|
+
;
|
|
204
|
+
}).reverse();
|
|
205
|
+
return (api)=>{
|
|
206
|
+
for (let fn of fns){
|
|
207
|
+
fn(api);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
186
211
|
function buildPluginApi(tailwindConfig, context, { variantList , variantMap , offsets , classList }) {
|
|
187
212
|
function getConfigValue(path, defaultValue) {
|
|
188
213
|
return path ? (0, _dlv).default(tailwindConfig, path, defaultValue) : tailwindConfig;
|
|
@@ -205,31 +230,21 @@ function buildPluginApi(tailwindConfig, context, { variantList , variantMap , of
|
|
|
205
230
|
if (typeof variantFunction !== "string") {
|
|
206
231
|
// Safelist public API functions
|
|
207
232
|
return ({ modifySelectors , container , separator })=>{
|
|
208
|
-
|
|
233
|
+
let result = variantFunction({
|
|
209
234
|
modifySelectors,
|
|
210
235
|
container,
|
|
211
236
|
separator
|
|
212
237
|
});
|
|
238
|
+
if (typeof result === "string" && !isValidVariantFormatString(result)) {
|
|
239
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
213
242
|
};
|
|
214
243
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
;
|
|
220
|
-
}
|
|
221
|
-
let [, name, params] = /@(.*?) (.*)/g.exec(str);
|
|
222
|
-
return ({ wrap })=>wrap(_postcss.default.atRule({
|
|
223
|
-
name,
|
|
224
|
-
params
|
|
225
|
-
}))
|
|
226
|
-
;
|
|
227
|
-
}).reverse();
|
|
228
|
-
return (api)=>{
|
|
229
|
-
for (let fn of fns){
|
|
230
|
-
fn(api);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
244
|
+
if (!isValidVariantFormatString(variantFunction)) {
|
|
245
|
+
throw new Error(`Your custom variant \`${variantName}\` has an invalid format string. Make sure it's an at-rule or contains a \`&\` placeholder.`);
|
|
246
|
+
}
|
|
247
|
+
return parseVariant(variantFunction);
|
|
233
248
|
});
|
|
234
249
|
insertInto(variantList, variantName, options);
|
|
235
250
|
variantMap.set(variantName, variantFunctions);
|