@unocss/autocomplete 66.6.6-beta.1 → 66.6.7
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.mjs +8 -13
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { escapeRegExp, toArray, uniq } from "@unocss/core";
|
|
2
2
|
import { Fzf, byLengthAsc, byStartAsc } from "fzf";
|
|
3
3
|
import { LRUCache } from "lru-cache";
|
|
4
|
-
|
|
5
4
|
//#region package.json
|
|
6
5
|
var name = "@unocss/autocomplete";
|
|
7
|
-
|
|
8
6
|
//#endregion
|
|
9
7
|
//#region src/utils.ts
|
|
10
8
|
function searchUsageBoundary(line, index, attributify = true) {
|
|
@@ -53,15 +51,14 @@ function searchAttrKey(content, cursor) {
|
|
|
53
51
|
function cartesian(arr) {
|
|
54
52
|
return arr.reduce((a, b) => {
|
|
55
53
|
const ret = [];
|
|
56
|
-
a.forEach((a
|
|
57
|
-
b.forEach((b
|
|
58
|
-
ret.push(a
|
|
54
|
+
a.forEach((a) => {
|
|
55
|
+
b.forEach((b) => {
|
|
56
|
+
ret.push(a.concat([b]));
|
|
59
57
|
});
|
|
60
58
|
});
|
|
61
59
|
return ret;
|
|
62
60
|
}, [[]]);
|
|
63
61
|
}
|
|
64
|
-
|
|
65
62
|
//#endregion
|
|
66
63
|
//#region src/parse.ts
|
|
67
64
|
var AutocompleteParseError = class extends Error {
|
|
@@ -243,7 +240,7 @@ function parseAutocomplete(template, theme = {}, extraShorthands = {}) {
|
|
|
243
240
|
function getValuesFromPartTemplate(part) {
|
|
244
241
|
if (part.type === "static") return [part.value];
|
|
245
242
|
if (part.type === "theme") return part.objects.flatMap((i) => {
|
|
246
|
-
const keys = Object.keys(i).filter((i
|
|
243
|
+
const keys = Object.keys(i).filter((i) => i && i[0] !== "_");
|
|
247
244
|
for (const key in i) {
|
|
248
245
|
const value = i[key];
|
|
249
246
|
if (value === null || value === void 0) continue;
|
|
@@ -251,7 +248,7 @@ function getValuesFromPartTemplate(part) {
|
|
|
251
248
|
const subKeys = getValuesFromPartTemplate({
|
|
252
249
|
type: "theme",
|
|
253
250
|
objects: [value]
|
|
254
|
-
}).map((i
|
|
251
|
+
}).map((i) => `${key}-${i}`);
|
|
255
252
|
keys.push(...subKeys);
|
|
256
253
|
}
|
|
257
254
|
}
|
|
@@ -263,7 +260,6 @@ function getValuesFromPartTemplate(part) {
|
|
|
263
260
|
function getAllCombination(parts) {
|
|
264
261
|
return uniq(cartesian(parts.map((i) => getValuesFromPartTemplate(i))).flatMap((i) => i.join("").replace("-DEFAULT", "")));
|
|
265
262
|
}
|
|
266
|
-
|
|
267
263
|
//#endregion
|
|
268
264
|
//#region src/create.ts
|
|
269
265
|
function createAutocomplete(uno, options = {}) {
|
|
@@ -289,7 +285,7 @@ function createAutocomplete(uno, options = {}) {
|
|
|
289
285
|
const a2zd = [...a2z, "-"];
|
|
290
286
|
const keys = a2z.flatMap((i) => [i, ...a2zd.map((j) => `${i}${j}`)]);
|
|
291
287
|
await Promise.all(keys.map((key) => suggest(key).then((i) => i.forEach((j) => matched.add(j)))));
|
|
292
|
-
await Promise.all([...matched].filter((i) => /^\w+$/.test(i) && i.length > 3).map((i) => suggest(`${i}-`).then((i
|
|
288
|
+
await Promise.all([...matched].filter((i) => /^\w+$/.test(i) && i.length > 3).map((i) => suggest(`${i}-`).then((i) => i.forEach((j) => matched.add(j)))));
|
|
293
289
|
return matched;
|
|
294
290
|
}
|
|
295
291
|
async function suggest(input, allowsEmptyInput = false) {
|
|
@@ -358,7 +354,7 @@ function createAutocomplete(uno, options = {}) {
|
|
|
358
354
|
return Array.from(uno.cache.entries()).filter((i) => i[1] && i[0].startsWith(input)).map((i) => i[0]);
|
|
359
355
|
}
|
|
360
356
|
async function suggestFromTemplates(input) {
|
|
361
|
-
return (await Promise.allSettled([Array.from(templateCache.values()).flatMap(({ suggest
|
|
357
|
+
return (await Promise.allSettled([Array.from(templateCache.values()).flatMap(({ suggest }) => suggest(input, matchType) ?? []), ...templates.filter((fn) => typeof fn === "function").map((fn) => fn(input))])).flatMap((i) => i.status === "fulfilled" ? i.value : []);
|
|
362
358
|
}
|
|
363
359
|
function reset() {
|
|
364
360
|
templateCache.clear();
|
|
@@ -389,6 +385,5 @@ function createAutocomplete(uno, options = {}) {
|
|
|
389
385
|
}).map((i) => prefix + i + suffix);
|
|
390
386
|
}
|
|
391
387
|
}
|
|
392
|
-
|
|
393
388
|
//#endregion
|
|
394
|
-
export { AutocompleteParseError, cartesian, createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchAttrKey, searchUsageBoundary, shorthands };
|
|
389
|
+
export { AutocompleteParseError, cartesian, createAutocomplete, ignoredThemeKeys, parseAutocomplete, searchAttrKey, searchUsageBoundary, shorthands };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/autocomplete",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.6.
|
|
4
|
+
"version": "66.6.7",
|
|
5
5
|
"description": "Autocomplete utils for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"lru-cache": "^11.2.6"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@unocss/core": "66.6.
|
|
36
|
+
"@unocss/core": "66.6.7"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"build": "tsdown --config-loader unrun",
|