@unocss/preset-attributify 0.52.0 → 0.52.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 +82 -70
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +82 -70
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -45,84 +45,96 @@ function variantAttributify(options = {}) {
|
|
|
45
45
|
const elementRE$1 = /(<\w[\w:\.$-]*\s)((?:'[^>]*?'|"[^>]*?"|`[^>]*?`|\{[^>]*?\}|[^>]*?)*)/g;
|
|
46
46
|
const valuedAttributeRE$1 = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=("[^"]*|'[^']*))?/g;
|
|
47
47
|
const splitterRE$1 = /[\s'"`;>]+/;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
48
|
+
function autocompleteExtractorAttributify(options) {
|
|
49
|
+
return {
|
|
50
|
+
name: "attributify",
|
|
51
|
+
extract: ({ content, cursor }) => {
|
|
52
|
+
const matchedElements = content.matchAll(elementRE$1);
|
|
53
|
+
let attrs;
|
|
54
|
+
let elPos = 0;
|
|
55
|
+
for (const match of matchedElements) {
|
|
56
|
+
const [, prefix, content2] = match;
|
|
57
|
+
const currentPos2 = match.index + prefix.length;
|
|
58
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + content2.length) {
|
|
59
|
+
elPos = currentPos2;
|
|
60
|
+
attrs = content2;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
64
|
+
if (!attrs)
|
|
65
|
+
return null;
|
|
66
|
+
const matchedAttributes = attrs.matchAll(valuedAttributeRE$1);
|
|
67
|
+
let attrsPos = 0;
|
|
68
|
+
let attrName;
|
|
69
|
+
let attrValues;
|
|
70
|
+
for (const match of matchedAttributes) {
|
|
71
|
+
const [matched, name, rawValues] = match;
|
|
72
|
+
const currentPos2 = elPos + match.index;
|
|
73
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + matched.length) {
|
|
74
|
+
attrsPos = currentPos2;
|
|
75
|
+
attrName = name;
|
|
76
|
+
attrValues = rawValues?.slice(1);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
77
79
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
if (!attrName)
|
|
81
|
+
return null;
|
|
82
|
+
if (attrName === "class" || attrName === "className" || attrName === ":class")
|
|
83
|
+
return null;
|
|
84
|
+
const hasPrefix = !!options?.prefix && attrName.startsWith(options.prefix);
|
|
85
|
+
if (options?.prefixedOnly && !hasPrefix)
|
|
86
|
+
return null;
|
|
87
|
+
const attrNameWithoutPrefix = hasPrefix ? attrName.slice(options.prefix.length) : attrName;
|
|
88
|
+
if (attrValues === void 0) {
|
|
89
|
+
return {
|
|
90
|
+
extracted: attrNameWithoutPrefix,
|
|
91
|
+
transformSuggestions(suggestion) {
|
|
92
|
+
if (hasPrefix)
|
|
93
|
+
return suggestion.map((s) => options.prefix + s);
|
|
94
|
+
else
|
|
95
|
+
return suggestion;
|
|
96
|
+
},
|
|
97
|
+
resolveReplacement(suggestion) {
|
|
98
|
+
return {
|
|
99
|
+
start: attrsPos,
|
|
100
|
+
end: attrsPos + attrName.length,
|
|
101
|
+
replacement: suggestion
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const attrValuePos = attrsPos + attrName.length + 2;
|
|
107
|
+
let matchSplit = splitterRE$1.exec(attrValues);
|
|
108
|
+
let currentPos = 0;
|
|
109
|
+
let value;
|
|
110
|
+
while (matchSplit) {
|
|
111
|
+
const [matched] = matchSplit;
|
|
112
|
+
if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
|
|
113
|
+
value = attrValues.slice(currentPos, currentPos + matchSplit.index);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
currentPos += matchSplit.index + matched.length;
|
|
117
|
+
matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
|
|
118
|
+
}
|
|
119
|
+
if (value === void 0)
|
|
120
|
+
value = attrValues.slice(currentPos);
|
|
121
|
+
const [, variants = "", body] = value.match(variantsRE) || [];
|
|
84
122
|
return {
|
|
85
|
-
extracted:
|
|
123
|
+
extracted: `${variants}${attrNameWithoutPrefix}-${body}`,
|
|
124
|
+
transformSuggestions(suggestions) {
|
|
125
|
+
return suggestions.filter((v) => v.startsWith(`${variants}${attrNameWithoutPrefix}-`)).map((v) => variants + v.slice(variants.length + attrNameWithoutPrefix.length + 1));
|
|
126
|
+
},
|
|
86
127
|
resolveReplacement(suggestion) {
|
|
87
128
|
return {
|
|
88
|
-
start:
|
|
89
|
-
end:
|
|
90
|
-
replacement: suggestion
|
|
129
|
+
start: currentPos + attrValuePos,
|
|
130
|
+
end: currentPos + attrValuePos + value.length,
|
|
131
|
+
replacement: variants + suggestion.slice(variants.length + attrNameWithoutPrefix.length + 1)
|
|
91
132
|
};
|
|
92
133
|
}
|
|
93
134
|
};
|
|
94
135
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
let currentPos = 0;
|
|
98
|
-
let value;
|
|
99
|
-
while (matchSplit) {
|
|
100
|
-
const [matched] = matchSplit;
|
|
101
|
-
if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
|
|
102
|
-
value = attrValues.slice(currentPos, currentPos + matchSplit.index);
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
currentPos += matchSplit.index + matched.length;
|
|
106
|
-
matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
|
|
107
|
-
}
|
|
108
|
-
if (value === void 0)
|
|
109
|
-
value = attrValues.slice(currentPos);
|
|
110
|
-
const [, variants = "", body] = value.match(variantsRE) || [];
|
|
111
|
-
return {
|
|
112
|
-
extracted: `${variants}${attrName}-${body}`,
|
|
113
|
-
transformSuggestions(suggestions) {
|
|
114
|
-
return suggestions.filter((v) => v.startsWith(`${variants}${attrName}-`)).map((v) => variants + v.slice(variants.length + attrName.length + 1));
|
|
115
|
-
},
|
|
116
|
-
resolveReplacement(suggestion) {
|
|
117
|
-
return {
|
|
118
|
-
start: currentPos + attrValuePos,
|
|
119
|
-
end: currentPos + attrValuePos + value.length,
|
|
120
|
-
replacement: variants + suggestion.slice(variants.length + attrName.length + 1)
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
};
|
|
136
|
+
};
|
|
137
|
+
}
|
|
126
138
|
|
|
127
139
|
const strippedPrefixes = [
|
|
128
140
|
"v-bind:",
|
|
@@ -184,7 +196,7 @@ function presetAttributify(options = {}) {
|
|
|
184
196
|
extractorAttributify(options)
|
|
185
197
|
];
|
|
186
198
|
const autocompleteExtractors = [
|
|
187
|
-
autocompleteExtractorAttributify
|
|
199
|
+
autocompleteExtractorAttributify(options)
|
|
188
200
|
];
|
|
189
201
|
return {
|
|
190
202
|
name: "@unocss/preset-attributify",
|
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ interface AttributifyOptions extends PresetOptions {
|
|
|
42
42
|
trueToNonValued?: boolean;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
declare
|
|
45
|
+
declare function autocompleteExtractorAttributify(options?: AttributifyOptions): AutoCompleteExtractor;
|
|
46
46
|
|
|
47
47
|
declare const defaultIgnoreAttributes: string[];
|
|
48
48
|
declare function extractorAttributify(options?: AttributifyOptions): Extractor;
|
package/dist/index.mjs
CHANGED
|
@@ -41,84 +41,96 @@ function variantAttributify(options = {}) {
|
|
|
41
41
|
const elementRE$1 = /(<\w[\w:\.$-]*\s)((?:'[^>]*?'|"[^>]*?"|`[^>]*?`|\{[^>]*?\}|[^>]*?)*)/g;
|
|
42
42
|
const valuedAttributeRE$1 = /([?]|(?!\d|-{2}|-\d)[a-zA-Z0-9\u00A0-\uFFFF-_:%-]+)(?:=("[^"]*|'[^']*))?/g;
|
|
43
43
|
const splitterRE$1 = /[\s'"`;>]+/;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
44
|
+
function autocompleteExtractorAttributify(options) {
|
|
45
|
+
return {
|
|
46
|
+
name: "attributify",
|
|
47
|
+
extract: ({ content, cursor }) => {
|
|
48
|
+
const matchedElements = content.matchAll(elementRE$1);
|
|
49
|
+
let attrs;
|
|
50
|
+
let elPos = 0;
|
|
51
|
+
for (const match of matchedElements) {
|
|
52
|
+
const [, prefix, content2] = match;
|
|
53
|
+
const currentPos2 = match.index + prefix.length;
|
|
54
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + content2.length) {
|
|
55
|
+
elPos = currentPos2;
|
|
56
|
+
attrs = content2;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
57
59
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
if (!attrs)
|
|
61
|
+
return null;
|
|
62
|
+
const matchedAttributes = attrs.matchAll(valuedAttributeRE$1);
|
|
63
|
+
let attrsPos = 0;
|
|
64
|
+
let attrName;
|
|
65
|
+
let attrValues;
|
|
66
|
+
for (const match of matchedAttributes) {
|
|
67
|
+
const [matched, name, rawValues] = match;
|
|
68
|
+
const currentPos2 = elPos + match.index;
|
|
69
|
+
if (cursor > currentPos2 && cursor <= currentPos2 + matched.length) {
|
|
70
|
+
attrsPos = currentPos2;
|
|
71
|
+
attrName = name;
|
|
72
|
+
attrValues = rawValues?.slice(1);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
if (!attrName)
|
|
77
|
+
return null;
|
|
78
|
+
if (attrName === "class" || attrName === "className" || attrName === ":class")
|
|
79
|
+
return null;
|
|
80
|
+
const hasPrefix = !!options?.prefix && attrName.startsWith(options.prefix);
|
|
81
|
+
if (options?.prefixedOnly && !hasPrefix)
|
|
82
|
+
return null;
|
|
83
|
+
const attrNameWithoutPrefix = hasPrefix ? attrName.slice(options.prefix.length) : attrName;
|
|
84
|
+
if (attrValues === void 0) {
|
|
85
|
+
return {
|
|
86
|
+
extracted: attrNameWithoutPrefix,
|
|
87
|
+
transformSuggestions(suggestion) {
|
|
88
|
+
if (hasPrefix)
|
|
89
|
+
return suggestion.map((s) => options.prefix + s);
|
|
90
|
+
else
|
|
91
|
+
return suggestion;
|
|
92
|
+
},
|
|
93
|
+
resolveReplacement(suggestion) {
|
|
94
|
+
return {
|
|
95
|
+
start: attrsPos,
|
|
96
|
+
end: attrsPos + attrName.length,
|
|
97
|
+
replacement: suggestion
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const attrValuePos = attrsPos + attrName.length + 2;
|
|
103
|
+
let matchSplit = splitterRE$1.exec(attrValues);
|
|
104
|
+
let currentPos = 0;
|
|
105
|
+
let value;
|
|
106
|
+
while (matchSplit) {
|
|
107
|
+
const [matched] = matchSplit;
|
|
108
|
+
if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
|
|
109
|
+
value = attrValues.slice(currentPos, currentPos + matchSplit.index);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
currentPos += matchSplit.index + matched.length;
|
|
113
|
+
matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
|
|
114
|
+
}
|
|
115
|
+
if (value === void 0)
|
|
116
|
+
value = attrValues.slice(currentPos);
|
|
117
|
+
const [, variants = "", body] = value.match(variantsRE) || [];
|
|
80
118
|
return {
|
|
81
|
-
extracted:
|
|
119
|
+
extracted: `${variants}${attrNameWithoutPrefix}-${body}`,
|
|
120
|
+
transformSuggestions(suggestions) {
|
|
121
|
+
return suggestions.filter((v) => v.startsWith(`${variants}${attrNameWithoutPrefix}-`)).map((v) => variants + v.slice(variants.length + attrNameWithoutPrefix.length + 1));
|
|
122
|
+
},
|
|
82
123
|
resolveReplacement(suggestion) {
|
|
83
124
|
return {
|
|
84
|
-
start:
|
|
85
|
-
end:
|
|
86
|
-
replacement: suggestion
|
|
125
|
+
start: currentPos + attrValuePos,
|
|
126
|
+
end: currentPos + attrValuePos + value.length,
|
|
127
|
+
replacement: variants + suggestion.slice(variants.length + attrNameWithoutPrefix.length + 1)
|
|
87
128
|
};
|
|
88
129
|
}
|
|
89
130
|
};
|
|
90
131
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
let currentPos = 0;
|
|
94
|
-
let value;
|
|
95
|
-
while (matchSplit) {
|
|
96
|
-
const [matched] = matchSplit;
|
|
97
|
-
if (cursor > attrValuePos + currentPos && cursor <= attrValuePos + currentPos + matchSplit.index) {
|
|
98
|
-
value = attrValues.slice(currentPos, currentPos + matchSplit.index);
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
currentPos += matchSplit.index + matched.length;
|
|
102
|
-
matchSplit = splitterRE$1.exec(attrValues.slice(currentPos));
|
|
103
|
-
}
|
|
104
|
-
if (value === void 0)
|
|
105
|
-
value = attrValues.slice(currentPos);
|
|
106
|
-
const [, variants = "", body] = value.match(variantsRE) || [];
|
|
107
|
-
return {
|
|
108
|
-
extracted: `${variants}${attrName}-${body}`,
|
|
109
|
-
transformSuggestions(suggestions) {
|
|
110
|
-
return suggestions.filter((v) => v.startsWith(`${variants}${attrName}-`)).map((v) => variants + v.slice(variants.length + attrName.length + 1));
|
|
111
|
-
},
|
|
112
|
-
resolveReplacement(suggestion) {
|
|
113
|
-
return {
|
|
114
|
-
start: currentPos + attrValuePos,
|
|
115
|
-
end: currentPos + attrValuePos + value.length,
|
|
116
|
-
replacement: variants + suggestion.slice(variants.length + attrName.length + 1)
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
};
|
|
132
|
+
};
|
|
133
|
+
}
|
|
122
134
|
|
|
123
135
|
const strippedPrefixes = [
|
|
124
136
|
"v-bind:",
|
|
@@ -180,7 +192,7 @@ function presetAttributify(options = {}) {
|
|
|
180
192
|
extractorAttributify(options)
|
|
181
193
|
];
|
|
182
194
|
const autocompleteExtractors = [
|
|
183
|
-
autocompleteExtractorAttributify
|
|
195
|
+
autocompleteExtractorAttributify(options)
|
|
184
196
|
];
|
|
185
197
|
return {
|
|
186
198
|
name: "@unocss/preset-attributify",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/preset-attributify",
|
|
3
|
-
"version": "0.52.
|
|
3
|
+
"version": "0.52.1",
|
|
4
4
|
"description": "Attributify preset for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@unocss/core": "0.52.
|
|
36
|
+
"@unocss/core": "0.52.1"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "unbuild",
|