@unocss/preset-attributify 0.18.0 → 0.20.1
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/dist/index.cjs +29 -27
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +29 -27
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -11,11 +11,11 @@ const strippedPrefixes = [
|
|
|
11
11
|
const splitterRE = /[\s'"`;]+/g;
|
|
12
12
|
const elementRE = /<\w[\w:\.$-]*\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
13
13
|
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=(["'])([^\2]*?)\2)?/g;
|
|
14
|
-
const extractorAttributify =
|
|
14
|
+
const extractorAttributify = {
|
|
15
15
|
name: "attributify",
|
|
16
|
-
extract({ code }) {
|
|
16
|
+
extract({ code, options: { ignoreAttributes, nonValuedAttribute } }) {
|
|
17
17
|
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
|
|
18
|
-
if (
|
|
18
|
+
if (ignoreAttributes?.includes(name))
|
|
19
19
|
return [];
|
|
20
20
|
for (const prefix of strippedPrefixes) {
|
|
21
21
|
if (name.startsWith(prefix)) {
|
|
@@ -24,7 +24,7 @@ const extractorAttributify = (options) => ({
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
if (!content) {
|
|
27
|
-
if (core.isValidSelector(name) &&
|
|
27
|
+
if (core.isValidSelector(name) && nonValuedAttribute !== false)
|
|
28
28
|
return [`[${name}=""]`];
|
|
29
29
|
return [];
|
|
30
30
|
}
|
|
@@ -36,37 +36,39 @@ const extractorAttributify = (options) => ({
|
|
|
36
36
|
});
|
|
37
37
|
return new Set(result);
|
|
38
38
|
}
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
|
|
41
41
|
const variantsRE = /^(.+\:\!?)?(.*?)$/;
|
|
42
|
-
const variantAttributify = (options
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
else
|
|
58
|
-
return `${variants}${name}-${body}`;
|
|
59
|
-
};
|
|
42
|
+
const variantAttributify = (input, { options: { prefix, prefixedOnly } }) => {
|
|
43
|
+
const match = core.isAttributifySelector(input);
|
|
44
|
+
if (!match)
|
|
45
|
+
return;
|
|
46
|
+
let name = match[1];
|
|
47
|
+
if (name.startsWith(prefix))
|
|
48
|
+
name = name.slice(prefix.length);
|
|
49
|
+
else if (prefixedOnly)
|
|
50
|
+
return;
|
|
51
|
+
const content = match[2];
|
|
52
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
53
|
+
if (body === "~" || !body)
|
|
54
|
+
return `${variants}${name}`;
|
|
55
|
+
else
|
|
56
|
+
return `${variants}${name}-${body}`;
|
|
60
57
|
};
|
|
61
58
|
|
|
62
|
-
const preset = (options) => {
|
|
59
|
+
const preset = (options = {}) => {
|
|
60
|
+
options.strict = options.strict ?? false;
|
|
61
|
+
options.prefix = options.prefix ?? "un-";
|
|
62
|
+
options.prefixedOnly = options.prefixedOnly ?? false;
|
|
63
|
+
options.nonValuedAttribute = options.nonValuedAttribute ?? true;
|
|
64
|
+
options.ignoreAttributes = options.ignoreAttributes ?? [];
|
|
63
65
|
const variants = [
|
|
64
|
-
variantAttributify
|
|
66
|
+
variantAttributify
|
|
65
67
|
];
|
|
66
68
|
const extractors = [
|
|
67
|
-
extractorAttributify
|
|
69
|
+
extractorAttributify
|
|
68
70
|
];
|
|
69
|
-
if (!options
|
|
71
|
+
if (!options.strict)
|
|
70
72
|
extractors.unshift(core.extractorSplit);
|
|
71
73
|
return {
|
|
72
74
|
name: "@unocss/preset-attributify",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Extractor, VariantFunction, Preset } from '@unocss/core';
|
|
1
|
+
import { PresetOptions, Extractor, VariantFunction, Preset } from '@unocss/core';
|
|
2
2
|
|
|
3
|
-
interface AttributifyOptions {
|
|
3
|
+
interface AttributifyOptions extends PresetOptions {
|
|
4
4
|
/**
|
|
5
5
|
* Only generate CSS for attributify or class
|
|
6
6
|
*
|
|
@@ -34,10 +34,10 @@ interface AttributifyOptions {
|
|
|
34
34
|
ignoreAttributes?: string[];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
declare const extractorAttributify:
|
|
37
|
+
declare const extractorAttributify: Extractor;
|
|
38
38
|
|
|
39
|
-
declare const variantAttributify:
|
|
39
|
+
declare const variantAttributify: VariantFunction;
|
|
40
40
|
|
|
41
|
-
declare const preset: (options?: AttributifyOptions
|
|
41
|
+
declare const preset: (options?: AttributifyOptions) => Preset;
|
|
42
42
|
|
|
43
43
|
export { AttributifyOptions, preset as default, extractorAttributify, variantAttributify };
|
package/dist/index.mjs
CHANGED
|
@@ -7,11 +7,11 @@ const strippedPrefixes = [
|
|
|
7
7
|
const splitterRE = /[\s'"`;]+/g;
|
|
8
8
|
const elementRE = /<\w[\w:\.$-]*\s((?:'[\s\S]*?'|"[\s\S]*?"|`[\s\S]*?`|\{[\s\S]*?\}|[\s\S]*?)*?)>/g;
|
|
9
9
|
const valuedAttributeRE = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=(["'])([^\2]*?)\2)?/g;
|
|
10
|
-
const extractorAttributify =
|
|
10
|
+
const extractorAttributify = {
|
|
11
11
|
name: "attributify",
|
|
12
|
-
extract({ code }) {
|
|
12
|
+
extract({ code, options: { ignoreAttributes, nonValuedAttribute } }) {
|
|
13
13
|
const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
|
|
14
|
-
if (
|
|
14
|
+
if (ignoreAttributes?.includes(name))
|
|
15
15
|
return [];
|
|
16
16
|
for (const prefix of strippedPrefixes) {
|
|
17
17
|
if (name.startsWith(prefix)) {
|
|
@@ -20,7 +20,7 @@ const extractorAttributify = (options) => ({
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
if (!content) {
|
|
23
|
-
if (isValidSelector(name) &&
|
|
23
|
+
if (isValidSelector(name) && nonValuedAttribute !== false)
|
|
24
24
|
return [`[${name}=""]`];
|
|
25
25
|
return [];
|
|
26
26
|
}
|
|
@@ -32,37 +32,39 @@ const extractorAttributify = (options) => ({
|
|
|
32
32
|
});
|
|
33
33
|
return new Set(result);
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
};
|
|
36
36
|
|
|
37
37
|
const variantsRE = /^(.+\:\!?)?(.*?)$/;
|
|
38
|
-
const variantAttributify = (options
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else
|
|
54
|
-
return `${variants}${name}-${body}`;
|
|
55
|
-
};
|
|
38
|
+
const variantAttributify = (input, { options: { prefix, prefixedOnly } }) => {
|
|
39
|
+
const match = isAttributifySelector(input);
|
|
40
|
+
if (!match)
|
|
41
|
+
return;
|
|
42
|
+
let name = match[1];
|
|
43
|
+
if (name.startsWith(prefix))
|
|
44
|
+
name = name.slice(prefix.length);
|
|
45
|
+
else if (prefixedOnly)
|
|
46
|
+
return;
|
|
47
|
+
const content = match[2];
|
|
48
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
49
|
+
if (body === "~" || !body)
|
|
50
|
+
return `${variants}${name}`;
|
|
51
|
+
else
|
|
52
|
+
return `${variants}${name}-${body}`;
|
|
56
53
|
};
|
|
57
54
|
|
|
58
|
-
const preset = (options) => {
|
|
55
|
+
const preset = (options = {}) => {
|
|
56
|
+
options.strict = options.strict ?? false;
|
|
57
|
+
options.prefix = options.prefix ?? "un-";
|
|
58
|
+
options.prefixedOnly = options.prefixedOnly ?? false;
|
|
59
|
+
options.nonValuedAttribute = options.nonValuedAttribute ?? true;
|
|
60
|
+
options.ignoreAttributes = options.ignoreAttributes ?? [];
|
|
59
61
|
const variants = [
|
|
60
|
-
variantAttributify
|
|
62
|
+
variantAttributify
|
|
61
63
|
];
|
|
62
64
|
const extractors = [
|
|
63
|
-
extractorAttributify
|
|
65
|
+
extractorAttributify
|
|
64
66
|
];
|
|
65
|
-
if (!options
|
|
67
|
+
if (!options.strict)
|
|
66
68
|
extractors.unshift(extractorSplit);
|
|
67
69
|
return {
|
|
68
70
|
name: "@unocss/preset-attributify",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-attributify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Attributify preset for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unocss/core": "0.
|
|
36
|
+
"@unocss/core": "0.20.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|