-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
30 lines (29 loc) · 1005 Bytes
/
index.ts
1
2
3
4
5
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
import plugin from 'tailwindcss/plugin.js';
export default plugin(({ matchUtilities }) => {
matchUtilities({
multi: (value) => {
if (!value[0]) return {};
const validQuotes = [`'`, `"`, `\``];
const ends = [value[0], value.slice(-1)[0]];
const valueIsQuoted = validQuotes.includes(value[0]);
if (valueIsQuoted && (value.length < 3 || ends[0] !== ends[1])) {
throw new Error(
`Invalid multi value: \`${value}\`. Quoted values must use matching quotes (e.g. ['...'], ["..."], or [\`...\`]).`
);
}
const escape = (str: string) => str.replace(/_/g, '\\_').replace(/ /g, '_');
const delimiter = /;(?![^[]*\])/;
const utilities = value
.slice(...(valueIsQuoted ? [1, -1] : []))
.split(delimiter)
.filter((str) => str.trim().length)
.map(escape)
.join(' ');
return !utilities.trim()
? {}
: {
[`@apply ${utilities}`]: {},
};
},
});
});