@unocss/autocomplete 0.44.7 → 0.45.4
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 +63 -37
- package/dist/index.mjs +63 -37
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -40,33 +40,43 @@ function parseAutocomplete(template, theme = {}) {
|
|
|
40
40
|
suggest
|
|
41
41
|
};
|
|
42
42
|
function handleNonGroup(input) {
|
|
43
|
-
handleRegexMatch(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return v
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
handleRegexMatch(
|
|
44
|
+
input,
|
|
45
|
+
/\$([\w\.\|]+)/g,
|
|
46
|
+
(m) => {
|
|
47
|
+
parts.push({
|
|
48
|
+
type: "theme",
|
|
49
|
+
objects: m[1].split("|").map((i) => {
|
|
50
|
+
return i.split(".").reduce((v, k) => {
|
|
51
|
+
if (!k || !v[k])
|
|
52
|
+
throw new Error(`Invalid theme key ${k}`);
|
|
53
|
+
return v[k];
|
|
54
|
+
}, theme);
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
(str) => {
|
|
59
|
+
parts.push({
|
|
60
|
+
type: "static",
|
|
61
|
+
value: str
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
);
|
|
60
65
|
}
|
|
61
66
|
function handleGroups(input) {
|
|
62
|
-
handleRegexMatch(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
handleRegexMatch(
|
|
68
|
+
input,
|
|
69
|
+
/\((.*?)\)/g,
|
|
70
|
+
(m) => {
|
|
71
|
+
parts.push({
|
|
72
|
+
type: "group",
|
|
73
|
+
values: m[1].split("|").sort((a, b) => b.length - a.length)
|
|
74
|
+
});
|
|
75
|
+
},
|
|
76
|
+
(str) => {
|
|
77
|
+
handleNonGroup(str);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
70
80
|
}
|
|
71
81
|
function suggest(input) {
|
|
72
82
|
let rest = input;
|
|
@@ -162,8 +172,12 @@ function createAutocomplete(uno) {
|
|
|
162
172
|
i,
|
|
163
173
|
...a2zd.map((j) => `${i}${j}`)
|
|
164
174
|
]);
|
|
165
|
-
await Promise.all(keys.map(
|
|
166
|
-
|
|
175
|
+
await Promise.all(keys.map(
|
|
176
|
+
(key) => suggest(key).then((i) => i.forEach((j) => matched.add(j)))
|
|
177
|
+
));
|
|
178
|
+
await Promise.all(
|
|
179
|
+
[...matched].filter((i) => i.match(/^\w+$/) && i.length > 3).map((i) => suggest(`${i}-`).then((i2) => i2.forEach((j) => matched.add(j))))
|
|
180
|
+
);
|
|
167
181
|
return matched;
|
|
168
182
|
}
|
|
169
183
|
function getParsed(template) {
|
|
@@ -182,13 +196,17 @@ function createAutocomplete(uno) {
|
|
|
182
196
|
idx = 0;
|
|
183
197
|
const variantPrefix = input.slice(0, idx);
|
|
184
198
|
const variantSuffix = input.slice(idx + input.length);
|
|
185
|
-
const result = processSuggestions(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
const result = processSuggestions(
|
|
200
|
+
await Promise.all([
|
|
201
|
+
suggestSelf(processed),
|
|
202
|
+
suggestStatic(processed),
|
|
203
|
+
suggestUnoCache(processed),
|
|
204
|
+
...suggestFromPreset(processed),
|
|
205
|
+
...suggestVariant(processed, variants)
|
|
206
|
+
]),
|
|
207
|
+
variantPrefix,
|
|
208
|
+
variantSuffix
|
|
209
|
+
);
|
|
192
210
|
cache.set(input, result);
|
|
193
211
|
return result;
|
|
194
212
|
}
|
|
@@ -235,10 +253,14 @@ function createAutocomplete(uno) {
|
|
|
235
253
|
return keys.filter((i) => i[1] && i[0].startsWith(input)).map((i) => i[0]);
|
|
236
254
|
}
|
|
237
255
|
function suggestFromPreset(input) {
|
|
238
|
-
return templates.map(
|
|
256
|
+
return templates.map(
|
|
257
|
+
(fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)
|
|
258
|
+
) || [];
|
|
239
259
|
}
|
|
240
260
|
function suggestVariant(input, used) {
|
|
241
|
-
return uno.config.variants.filter((v) => v.autocomplete && (v.multiPass || !used.has(v))).flatMap((v) => core.toArray(v.autocomplete || [])).map(
|
|
261
|
+
return uno.config.variants.filter((v) => v.autocomplete && (v.multiPass || !used.has(v))).flatMap((v) => core.toArray(v.autocomplete || [])).map(
|
|
262
|
+
(fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)
|
|
263
|
+
);
|
|
242
264
|
}
|
|
243
265
|
function reset() {
|
|
244
266
|
templateCache.clear();
|
|
@@ -248,7 +270,11 @@ function createAutocomplete(uno) {
|
|
|
248
270
|
...uno.config.shortcuts.filter((i) => typeof i[0] === "string").map((i) => i[0])
|
|
249
271
|
];
|
|
250
272
|
templates.length = 0;
|
|
251
|
-
templates.push(
|
|
273
|
+
templates.push(
|
|
274
|
+
...uno.config.autocomplete.templates || [],
|
|
275
|
+
...uno.config.rulesDynamic.flatMap((i) => core.toArray(i?.[2]?.autocomplete || [])),
|
|
276
|
+
...uno.config.shortcuts.flatMap((i) => core.toArray(i?.[2]?.autocomplete || []))
|
|
277
|
+
);
|
|
252
278
|
}
|
|
253
279
|
function processSuggestions(suggestions, prefix = "", suffix = "") {
|
|
254
280
|
return core.uniq(suggestions.flat()).filter((i) => !!(i && !i.match(/-$/))).sort((a, b) => {
|
package/dist/index.mjs
CHANGED
|
@@ -32,33 +32,43 @@ function parseAutocomplete(template, theme = {}) {
|
|
|
32
32
|
suggest
|
|
33
33
|
};
|
|
34
34
|
function handleNonGroup(input) {
|
|
35
|
-
handleRegexMatch(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return v
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
35
|
+
handleRegexMatch(
|
|
36
|
+
input,
|
|
37
|
+
/\$([\w\.\|]+)/g,
|
|
38
|
+
(m) => {
|
|
39
|
+
parts.push({
|
|
40
|
+
type: "theme",
|
|
41
|
+
objects: m[1].split("|").map((i) => {
|
|
42
|
+
return i.split(".").reduce((v, k) => {
|
|
43
|
+
if (!k || !v[k])
|
|
44
|
+
throw new Error(`Invalid theme key ${k}`);
|
|
45
|
+
return v[k];
|
|
46
|
+
}, theme);
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
(str) => {
|
|
51
|
+
parts.push({
|
|
52
|
+
type: "static",
|
|
53
|
+
value: str
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
);
|
|
52
57
|
}
|
|
53
58
|
function handleGroups(input) {
|
|
54
|
-
handleRegexMatch(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
handleRegexMatch(
|
|
60
|
+
input,
|
|
61
|
+
/\((.*?)\)/g,
|
|
62
|
+
(m) => {
|
|
63
|
+
parts.push({
|
|
64
|
+
type: "group",
|
|
65
|
+
values: m[1].split("|").sort((a, b) => b.length - a.length)
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
(str) => {
|
|
69
|
+
handleNonGroup(str);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
62
72
|
}
|
|
63
73
|
function suggest(input) {
|
|
64
74
|
let rest = input;
|
|
@@ -154,8 +164,12 @@ function createAutocomplete(uno) {
|
|
|
154
164
|
i,
|
|
155
165
|
...a2zd.map((j) => `${i}${j}`)
|
|
156
166
|
]);
|
|
157
|
-
await Promise.all(keys.map(
|
|
158
|
-
|
|
167
|
+
await Promise.all(keys.map(
|
|
168
|
+
(key) => suggest(key).then((i) => i.forEach((j) => matched.add(j)))
|
|
169
|
+
));
|
|
170
|
+
await Promise.all(
|
|
171
|
+
[...matched].filter((i) => i.match(/^\w+$/) && i.length > 3).map((i) => suggest(`${i}-`).then((i2) => i2.forEach((j) => matched.add(j))))
|
|
172
|
+
);
|
|
159
173
|
return matched;
|
|
160
174
|
}
|
|
161
175
|
function getParsed(template) {
|
|
@@ -174,13 +188,17 @@ function createAutocomplete(uno) {
|
|
|
174
188
|
idx = 0;
|
|
175
189
|
const variantPrefix = input.slice(0, idx);
|
|
176
190
|
const variantSuffix = input.slice(idx + input.length);
|
|
177
|
-
const result = processSuggestions(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
191
|
+
const result = processSuggestions(
|
|
192
|
+
await Promise.all([
|
|
193
|
+
suggestSelf(processed),
|
|
194
|
+
suggestStatic(processed),
|
|
195
|
+
suggestUnoCache(processed),
|
|
196
|
+
...suggestFromPreset(processed),
|
|
197
|
+
...suggestVariant(processed, variants)
|
|
198
|
+
]),
|
|
199
|
+
variantPrefix,
|
|
200
|
+
variantSuffix
|
|
201
|
+
);
|
|
184
202
|
cache.set(input, result);
|
|
185
203
|
return result;
|
|
186
204
|
}
|
|
@@ -227,10 +245,14 @@ function createAutocomplete(uno) {
|
|
|
227
245
|
return keys.filter((i) => i[1] && i[0].startsWith(input)).map((i) => i[0]);
|
|
228
246
|
}
|
|
229
247
|
function suggestFromPreset(input) {
|
|
230
|
-
return templates.map(
|
|
248
|
+
return templates.map(
|
|
249
|
+
(fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)
|
|
250
|
+
) || [];
|
|
231
251
|
}
|
|
232
252
|
function suggestVariant(input, used) {
|
|
233
|
-
return uno.config.variants.filter((v) => v.autocomplete && (v.multiPass || !used.has(v))).flatMap((v) => toArray(v.autocomplete || [])).map(
|
|
253
|
+
return uno.config.variants.filter((v) => v.autocomplete && (v.multiPass || !used.has(v))).flatMap((v) => toArray(v.autocomplete || [])).map(
|
|
254
|
+
(fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)
|
|
255
|
+
);
|
|
234
256
|
}
|
|
235
257
|
function reset() {
|
|
236
258
|
templateCache.clear();
|
|
@@ -240,7 +262,11 @@ function createAutocomplete(uno) {
|
|
|
240
262
|
...uno.config.shortcuts.filter((i) => typeof i[0] === "string").map((i) => i[0])
|
|
241
263
|
];
|
|
242
264
|
templates.length = 0;
|
|
243
|
-
templates.push(
|
|
265
|
+
templates.push(
|
|
266
|
+
...uno.config.autocomplete.templates || [],
|
|
267
|
+
...uno.config.rulesDynamic.flatMap((i) => toArray(i?.[2]?.autocomplete || [])),
|
|
268
|
+
...uno.config.shortcuts.flatMap((i) => toArray(i?.[2]?.autocomplete || []))
|
|
269
|
+
);
|
|
244
270
|
}
|
|
245
271
|
function processSuggestions(suggestions, prefix = "", suffix = "") {
|
|
246
272
|
return uniq(suggestions.flat()).filter((i) => !!(i && !i.match(/-$/))).sort((a, b) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/autocomplete",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.4",
|
|
4
4
|
"description": "Autocomplete utils for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"lru-cache": "^7.
|
|
35
|
+
"lru-cache": "^7.13.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@unocss/core": "0.
|
|
38
|
+
"@unocss/core": "0.45.4"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "unbuild",
|