@unocss/preset-attributify 0.29.6 → 0.30.0
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 +113 -23
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +113 -25
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -4,6 +4,110 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const core = require('@unocss/core');
|
|
6
6
|
|
|
7
|
+
const variantsRE = /^(?!\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
8
|
+
const variantAttributify = (options = {}) => {
|
|
9
|
+
const prefix = options.prefix ?? "un-";
|
|
10
|
+
const prefixedOnly = options.prefixedOnly ?? false;
|
|
11
|
+
return (input) => {
|
|
12
|
+
const match = core.isAttributifySelector(input);
|
|
13
|
+
if (!match)
|
|
14
|
+
return;
|
|
15
|
+
let name = match[1];
|
|
16
|
+
if (name.startsWith(prefix))
|
|
17
|
+
name = name.slice(prefix.length);
|
|
18
|
+
else if (prefixedOnly)
|
|
19
|
+
return;
|
|
20
|
+
const content = match[2];
|
|
21
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
22
|
+
if (body === "~" || !body)
|
|
23
|
+
return `${variants}${name}`;
|
|
24
|
+
else
|
|
25
|
+
return `${variants}${name}-${body}`;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const elementRE$1 = /(<\w[\w:\.$-]*\s)((?:'[^>]*?'|"[^>]*?"|`[^>]*?`|\{[^>]*?\}|[^>]*?)*)/g;
|
|
30
|
+
const valuedAttributeRE$1 = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=("[^"]*|'[^']*))?/g;
|
|
31
|
+
const splitterRE$1 = /[\s'"`;>]+/;
|
|
32
|
+
const autocompleteExtractorAttributify = {
|
|
33
|
+
name: "attributify",
|
|
34
|
+
extract: ({ content, cursor }) => {
|
|
35
|
+
const matchedElements = content.matchAll(elementRE$1);
|
|
36
|
+
let attrs;
|
|
37
|
+
let elPos = 0;
|
|
38
|
+
for (const match of matchedElements) {
|
|
39
|
+
const [, prefix, content2] = match;
|
|
40
|
+
const currentPos2 = match.index + prefix.length;
|
|
41
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + content2.length) {
|
|
42
|
+
elPos = currentPos2;
|
|
43
|
+
attrs = content2;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!attrs)
|
|
48
|
+
return null;
|
|
49
|
+
const matchedAttributes = attrs.matchAll(valuedAttributeRE$1);
|
|
50
|
+
let attrsPos = 0;
|
|
51
|
+
let attrName;
|
|
52
|
+
let attrValues;
|
|
53
|
+
for (const match of matchedAttributes) {
|
|
54
|
+
const [matched, name, rawValues] = match;
|
|
55
|
+
const currentPos2 = elPos + match.index;
|
|
56
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + matched.length) {
|
|
57
|
+
attrsPos = currentPos2;
|
|
58
|
+
attrName = name;
|
|
59
|
+
attrValues = rawValues?.slice(1);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (!attrName)
|
|
64
|
+
return null;
|
|
65
|
+
if (attrName === "class" || attrName === "className")
|
|
66
|
+
return null;
|
|
67
|
+
if (attrValues === void 0) {
|
|
68
|
+
return {
|
|
69
|
+
extracted: attrName,
|
|
70
|
+
resolveReplacement(suggestion) {
|
|
71
|
+
return {
|
|
72
|
+
start: attrsPos,
|
|
73
|
+
end: attrsPos + attrName.length,
|
|
74
|
+
replacement: suggestion
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
const attrValuePos = attrsPos + attrName.length + 2;
|
|
80
|
+
let matchSplit = splitterRE$1.exec(attrValues);
|
|
81
|
+
let currentPos = 0;
|
|
82
|
+
let value;
|
|
83
|
+
while (matchSplit) {
|
|
84
|
+
const [matched] = matchSplit;
|
|
85
|
+
if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
|
|
86
|
+
value = attrValues.slice(currentPos, currentPos + matchSplit.index);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
currentPos += matchSplit.index + matched.length;
|
|
90
|
+
matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
|
|
91
|
+
}
|
|
92
|
+
if (value === void 0)
|
|
93
|
+
value = attrValues.slice(currentPos);
|
|
94
|
+
const [, variants = "", body] = value.match(variantsRE) || [];
|
|
95
|
+
return {
|
|
96
|
+
extracted: `${variants}${attrName}-${body}`,
|
|
97
|
+
transformSuggestions(suggestions) {
|
|
98
|
+
return suggestions.filter((v) => v.startsWith(`${variants}${attrName}-`)).map((v) => variants + v.slice(variants.length + attrName.length + 1));
|
|
99
|
+
},
|
|
100
|
+
resolveReplacement(suggestion) {
|
|
101
|
+
return {
|
|
102
|
+
start: currentPos + attrValuePos,
|
|
103
|
+
end: currentPos + attrValuePos + value.length,
|
|
104
|
+
replacement: variants + suggestion.slice(variants.length + attrName.length + 1)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
7
111
|
const strippedPrefixes = [
|
|
8
112
|
"v-bind:",
|
|
9
113
|
":"
|
|
@@ -42,28 +146,6 @@ const extractorAttributify = (options) => {
|
|
|
42
146
|
};
|
|
43
147
|
};
|
|
44
148
|
|
|
45
|
-
const variantsRE = /^(?!\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
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
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
149
|
const preset = (options = {}) => {
|
|
68
150
|
options.strict = options.strict ?? false;
|
|
69
151
|
options.prefix = options.prefix ?? "un-";
|
|
@@ -76,16 +158,24 @@ const preset = (options = {}) => {
|
|
|
76
158
|
const extractors = [
|
|
77
159
|
extractorAttributify(options)
|
|
78
160
|
];
|
|
161
|
+
const autocompleteExtractors = [
|
|
162
|
+
autocompleteExtractorAttributify
|
|
163
|
+
];
|
|
79
164
|
if (!options.strict)
|
|
80
165
|
extractors.unshift(core.extractorSplit);
|
|
81
166
|
return {
|
|
82
167
|
name: "@unocss/preset-attributify",
|
|
83
168
|
variants,
|
|
84
169
|
extractors,
|
|
85
|
-
options
|
|
170
|
+
options,
|
|
171
|
+
autocomplete: {
|
|
172
|
+
extractors: autocompleteExtractors
|
|
173
|
+
}
|
|
86
174
|
};
|
|
87
175
|
};
|
|
88
176
|
|
|
177
|
+
exports.autocompleteExtractorAttributify = autocompleteExtractorAttributify;
|
|
89
178
|
exports["default"] = preset;
|
|
90
179
|
exports.extractorAttributify = extractorAttributify;
|
|
91
180
|
exports.variantAttributify = variantAttributify;
|
|
181
|
+
exports.variantsRE = variantsRE;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PresetOptions, Extractor, VariantFunction, Preset } from '@unocss/core';
|
|
1
|
+
import { PresetOptions, AutoCompleteExtractor, Extractor, VariantFunction, Preset } from '@unocss/core';
|
|
2
2
|
|
|
3
3
|
interface AttributifyOptions extends PresetOptions {
|
|
4
4
|
/**
|
|
@@ -34,10 +34,13 @@ interface AttributifyOptions extends PresetOptions {
|
|
|
34
34
|
ignoreAttributes?: string[];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
declare const autocompleteExtractorAttributify: AutoCompleteExtractor;
|
|
38
|
+
|
|
37
39
|
declare const extractorAttributify: (options?: AttributifyOptions | undefined) => Extractor;
|
|
38
40
|
|
|
41
|
+
declare const variantsRE: RegExp;
|
|
39
42
|
declare const variantAttributify: (options?: AttributifyOptions) => VariantFunction;
|
|
40
43
|
|
|
41
44
|
declare const preset: (options?: AttributifyOptions) => Preset;
|
|
42
45
|
|
|
43
|
-
export { AttributifyOptions, preset as default, extractorAttributify, variantAttributify };
|
|
46
|
+
export { AttributifyOptions, autocompleteExtractorAttributify, preset as default, extractorAttributify, variantAttributify, variantsRE };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,108 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isAttributifySelector, isValidSelector, extractorSplit } from '@unocss/core';
|
|
2
|
+
|
|
3
|
+
const variantsRE = /^(?!\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
4
|
+
const variantAttributify = (options = {}) => {
|
|
5
|
+
const prefix = options.prefix ?? "un-";
|
|
6
|
+
const prefixedOnly = options.prefixedOnly ?? false;
|
|
7
|
+
return (input) => {
|
|
8
|
+
const match = isAttributifySelector(input);
|
|
9
|
+
if (!match)
|
|
10
|
+
return;
|
|
11
|
+
let name = match[1];
|
|
12
|
+
if (name.startsWith(prefix))
|
|
13
|
+
name = name.slice(prefix.length);
|
|
14
|
+
else if (prefixedOnly)
|
|
15
|
+
return;
|
|
16
|
+
const content = match[2];
|
|
17
|
+
const [, variants = "", body = content] = content.match(variantsRE) || [];
|
|
18
|
+
if (body === "~" || !body)
|
|
19
|
+
return `${variants}${name}`;
|
|
20
|
+
else
|
|
21
|
+
return `${variants}${name}-${body}`;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const elementRE$1 = /(<\w[\w:\.$-]*\s)((?:'[^>]*?'|"[^>]*?"|`[^>]*?`|\{[^>]*?\}|[^>]*?)*)/g;
|
|
26
|
+
const valuedAttributeRE$1 = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=("[^"]*|'[^']*))?/g;
|
|
27
|
+
const splitterRE$1 = /[\s'"`;>]+/;
|
|
28
|
+
const autocompleteExtractorAttributify = {
|
|
29
|
+
name: "attributify",
|
|
30
|
+
extract: ({ content, cursor }) => {
|
|
31
|
+
const matchedElements = content.matchAll(elementRE$1);
|
|
32
|
+
let attrs;
|
|
33
|
+
let elPos = 0;
|
|
34
|
+
for (const match of matchedElements) {
|
|
35
|
+
const [, prefix, content2] = match;
|
|
36
|
+
const currentPos2 = match.index + prefix.length;
|
|
37
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + content2.length) {
|
|
38
|
+
elPos = currentPos2;
|
|
39
|
+
attrs = content2;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!attrs)
|
|
44
|
+
return null;
|
|
45
|
+
const matchedAttributes = attrs.matchAll(valuedAttributeRE$1);
|
|
46
|
+
let attrsPos = 0;
|
|
47
|
+
let attrName;
|
|
48
|
+
let attrValues;
|
|
49
|
+
for (const match of matchedAttributes) {
|
|
50
|
+
const [matched, name, rawValues] = match;
|
|
51
|
+
const currentPos2 = elPos + match.index;
|
|
52
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + matched.length) {
|
|
53
|
+
attrsPos = currentPos2;
|
|
54
|
+
attrName = name;
|
|
55
|
+
attrValues = rawValues?.slice(1);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!attrName)
|
|
60
|
+
return null;
|
|
61
|
+
if (attrName === "class" || attrName === "className")
|
|
62
|
+
return null;
|
|
63
|
+
if (attrValues === void 0) {
|
|
64
|
+
return {
|
|
65
|
+
extracted: attrName,
|
|
66
|
+
resolveReplacement(suggestion) {
|
|
67
|
+
return {
|
|
68
|
+
start: attrsPos,
|
|
69
|
+
end: attrsPos + attrName.length,
|
|
70
|
+
replacement: suggestion
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const attrValuePos = attrsPos + attrName.length + 2;
|
|
76
|
+
let matchSplit = splitterRE$1.exec(attrValues);
|
|
77
|
+
let currentPos = 0;
|
|
78
|
+
let value;
|
|
79
|
+
while (matchSplit) {
|
|
80
|
+
const [matched] = matchSplit;
|
|
81
|
+
if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
|
|
82
|
+
value = attrValues.slice(currentPos, currentPos + matchSplit.index);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
currentPos += matchSplit.index + matched.length;
|
|
86
|
+
matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
|
|
87
|
+
}
|
|
88
|
+
if (value === void 0)
|
|
89
|
+
value = attrValues.slice(currentPos);
|
|
90
|
+
const [, variants = "", body] = value.match(variantsRE) || [];
|
|
91
|
+
return {
|
|
92
|
+
extracted: `${variants}${attrName}-${body}`,
|
|
93
|
+
transformSuggestions(suggestions) {
|
|
94
|
+
return suggestions.filter((v) => v.startsWith(`${variants}${attrName}-`)).map((v) => variants + v.slice(variants.length + attrName.length + 1));
|
|
95
|
+
},
|
|
96
|
+
resolveReplacement(suggestion) {
|
|
97
|
+
return {
|
|
98
|
+
start: currentPos + attrValuePos,
|
|
99
|
+
end: currentPos + attrValuePos + value.length,
|
|
100
|
+
replacement: variants + suggestion.slice(variants.length + attrName.length + 1)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
};
|
|
2
106
|
|
|
3
107
|
const strippedPrefixes = [
|
|
4
108
|
"v-bind:",
|
|
@@ -38,28 +142,6 @@ const extractorAttributify = (options) => {
|
|
|
38
142
|
};
|
|
39
143
|
};
|
|
40
144
|
|
|
41
|
-
const variantsRE = /^(?!\[(?:[^:]+):(?:.+)\]$)((?:.+:)?!?)?(.*)$/;
|
|
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
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
145
|
const preset = (options = {}) => {
|
|
64
146
|
options.strict = options.strict ?? false;
|
|
65
147
|
options.prefix = options.prefix ?? "un-";
|
|
@@ -72,14 +154,20 @@ const preset = (options = {}) => {
|
|
|
72
154
|
const extractors = [
|
|
73
155
|
extractorAttributify(options)
|
|
74
156
|
];
|
|
157
|
+
const autocompleteExtractors = [
|
|
158
|
+
autocompleteExtractorAttributify
|
|
159
|
+
];
|
|
75
160
|
if (!options.strict)
|
|
76
161
|
extractors.unshift(extractorSplit);
|
|
77
162
|
return {
|
|
78
163
|
name: "@unocss/preset-attributify",
|
|
79
164
|
variants,
|
|
80
165
|
extractors,
|
|
81
|
-
options
|
|
166
|
+
options,
|
|
167
|
+
autocomplete: {
|
|
168
|
+
extractors: autocompleteExtractors
|
|
169
|
+
}
|
|
82
170
|
};
|
|
83
171
|
};
|
|
84
172
|
|
|
85
|
-
export { preset as default, extractorAttributify, variantAttributify };
|
|
173
|
+
export { autocompleteExtractorAttributify, preset as default, extractorAttributify, variantAttributify, variantsRE };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-attributify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Attributify preset for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"sideEffects": false,
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unocss/core": "0.
|
|
36
|
+
"@unocss/core": "0.30.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|