@unocss/preset-attributify 0.20.1 → 0.21.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 CHANGED
@@ -11,49 +11,57 @@ 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 = {
15
- name: "attributify",
16
- extract({ code, options: { ignoreAttributes, nonValuedAttribute } }) {
17
- const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
18
- if (ignoreAttributes?.includes(name))
19
- return [];
20
- for (const prefix of strippedPrefixes) {
21
- if (name.startsWith(prefix)) {
22
- name = name.slice(prefix.length);
23
- break;
14
+ const extractorAttributify = (options) => {
15
+ const ignoreAttributes = options?.ignoreAttributes ?? [];
16
+ const nonValuedAttribute = options?.nonValuedAttribute ?? true;
17
+ return {
18
+ name: "attributify",
19
+ extract({ code }) {
20
+ const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
21
+ if (ignoreAttributes.includes(name))
22
+ return [];
23
+ for (const prefix of strippedPrefixes) {
24
+ if (name.startsWith(prefix)) {
25
+ name = name.slice(prefix.length);
26
+ break;
27
+ }
28
+ }
29
+ if (!content) {
30
+ if (core.isValidSelector(name) && nonValuedAttribute !== false)
31
+ return [`[${name}=""]`];
32
+ return [];
33
+ }
34
+ if (["class", "className"].includes(name)) {
35
+ return content.split(splitterRE).filter(core.isValidSelector);
36
+ } else {
37
+ return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
24
38
  }
25
- }
26
- if (!content) {
27
- if (core.isValidSelector(name) && nonValuedAttribute !== false)
28
- return [`[${name}=""]`];
29
- return [];
30
- }
31
- if (["class", "className"].includes(name)) {
32
- return content.split(splitterRE).filter(core.isValidSelector);
33
- } else {
34
- return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
35
- }
36
- });
37
- return new Set(result);
38
- }
39
+ });
40
+ return new Set(result);
41
+ }
42
+ };
39
43
  };
40
44
 
41
45
  const variantsRE = /^(.+\:\!?)?(.*?)$/;
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}`;
46
+ const variantAttributify = (options = {}) => {
47
+ const prefix = options.prefix ?? "un-";
48
+ const prefixedOnly = options.prefixedOnly ?? false;
49
+ return (input) => {
50
+ const match = core.isAttributifySelector(input);
51
+ if (!match)
52
+ return;
53
+ let name = match[1];
54
+ if (name.startsWith(prefix))
55
+ name = name.slice(prefix.length);
56
+ else if (prefixedOnly)
57
+ return;
58
+ const content = match[2];
59
+ const [, variants = "", body = content] = content.match(variantsRE) || [];
60
+ if (body === "~" || !body)
61
+ return `${variants}${name}`;
62
+ else
63
+ return `${variants}${name}-${body}`;
64
+ };
57
65
  };
58
66
 
59
67
  const preset = (options = {}) => {
@@ -63,10 +71,10 @@ const preset = (options = {}) => {
63
71
  options.nonValuedAttribute = options.nonValuedAttribute ?? true;
64
72
  options.ignoreAttributes = options.ignoreAttributes ?? [];
65
73
  const variants = [
66
- variantAttributify
74
+ variantAttributify(options)
67
75
  ];
68
76
  const extractors = [
69
- extractorAttributify
77
+ extractorAttributify(options)
70
78
  ];
71
79
  if (!options.strict)
72
80
  extractors.unshift(core.extractorSplit);
package/dist/index.d.ts CHANGED
@@ -34,9 +34,9 @@ interface AttributifyOptions extends PresetOptions {
34
34
  ignoreAttributes?: string[];
35
35
  }
36
36
 
37
- declare const extractorAttributify: Extractor;
37
+ declare const extractorAttributify: (options?: AttributifyOptions | undefined) => Extractor;
38
38
 
39
- declare const variantAttributify: VariantFunction;
39
+ declare const variantAttributify: (options?: AttributifyOptions) => VariantFunction;
40
40
 
41
41
  declare const preset: (options?: AttributifyOptions) => Preset;
42
42
 
package/dist/index.mjs CHANGED
@@ -7,49 +7,57 @@ 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 = {
11
- name: "attributify",
12
- extract({ code, options: { ignoreAttributes, nonValuedAttribute } }) {
13
- const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
14
- if (ignoreAttributes?.includes(name))
15
- return [];
16
- for (const prefix of strippedPrefixes) {
17
- if (name.startsWith(prefix)) {
18
- name = name.slice(prefix.length);
19
- break;
10
+ const extractorAttributify = (options) => {
11
+ const ignoreAttributes = options?.ignoreAttributes ?? [];
12
+ const nonValuedAttribute = options?.nonValuedAttribute ?? true;
13
+ return {
14
+ name: "attributify",
15
+ extract({ code }) {
16
+ const result = Array.from(code.matchAll(elementRE)).flatMap((match) => Array.from((match[1] || "").matchAll(valuedAttributeRE))).flatMap(([, name, _, content]) => {
17
+ if (ignoreAttributes.includes(name))
18
+ return [];
19
+ for (const prefix of strippedPrefixes) {
20
+ if (name.startsWith(prefix)) {
21
+ name = name.slice(prefix.length);
22
+ break;
23
+ }
24
+ }
25
+ if (!content) {
26
+ if (isValidSelector(name) && nonValuedAttribute !== false)
27
+ return [`[${name}=""]`];
28
+ return [];
29
+ }
30
+ if (["class", "className"].includes(name)) {
31
+ return content.split(splitterRE).filter(isValidSelector);
32
+ } else {
33
+ return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
20
34
  }
21
- }
22
- if (!content) {
23
- if (isValidSelector(name) && nonValuedAttribute !== false)
24
- return [`[${name}=""]`];
25
- return [];
26
- }
27
- if (["class", "className"].includes(name)) {
28
- return content.split(splitterRE).filter(isValidSelector);
29
- } else {
30
- return content.split(splitterRE).filter(Boolean).map((v) => `[${name}~="${v}"]`);
31
- }
32
- });
33
- return new Set(result);
34
- }
35
+ });
36
+ return new Set(result);
37
+ }
38
+ };
35
39
  };
36
40
 
37
41
  const variantsRE = /^(.+\:\!?)?(.*?)$/;
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}`;
42
+ const variantAttributify = (options = {}) => {
43
+ const prefix = options.prefix ?? "un-";
44
+ const prefixedOnly = options.prefixedOnly ?? false;
45
+ return (input) => {
46
+ const match = isAttributifySelector(input);
47
+ if (!match)
48
+ return;
49
+ let name = match[1];
50
+ if (name.startsWith(prefix))
51
+ name = name.slice(prefix.length);
52
+ else if (prefixedOnly)
53
+ return;
54
+ const content = match[2];
55
+ const [, variants = "", body = content] = content.match(variantsRE) || [];
56
+ if (body === "~" || !body)
57
+ return `${variants}${name}`;
58
+ else
59
+ return `${variants}${name}-${body}`;
60
+ };
53
61
  };
54
62
 
55
63
  const preset = (options = {}) => {
@@ -59,10 +67,10 @@ const preset = (options = {}) => {
59
67
  options.nonValuedAttribute = options.nonValuedAttribute ?? true;
60
68
  options.ignoreAttributes = options.ignoreAttributes ?? [];
61
69
  const variants = [
62
- variantAttributify
70
+ variantAttributify(options)
63
71
  ];
64
72
  const extractors = [
65
- extractorAttributify
73
+ extractorAttributify(options)
66
74
  ];
67
75
  if (!options.strict)
68
76
  extractors.unshift(extractorSplit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/preset-attributify",
3
- "version": "0.20.1",
3
+ "version": "0.21.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.20.1"
36
+ "@unocss/core": "0.21.1"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "unbuild",