@unocss/autocomplete 0.44.7 → 0.45.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
@@ -40,33 +40,43 @@ function parseAutocomplete(template, theme = {}) {
40
40
  suggest
41
41
  };
42
42
  function handleNonGroup(input) {
43
- handleRegexMatch(input, /\$([\w\.\|]+)/g, (m) => {
44
- parts.push({
45
- type: "theme",
46
- objects: m[1].split("|").map((i) => {
47
- return i.split(".").reduce((v, k) => {
48
- if (!k || !v[k])
49
- throw new Error(`Invalid theme key ${k}`);
50
- return v[k];
51
- }, theme);
52
- })
53
- });
54
- }, (str) => {
55
- parts.push({
56
- type: "static",
57
- value: str
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(input, /\((.*?)\)/g, (m) => {
63
- parts.push({
64
- type: "group",
65
- values: m[1].split("|").sort((a, b) => b.length - a.length)
66
- });
67
- }, (str) => {
68
- handleNonGroup(str);
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((key) => suggest(key).then((i) => i.forEach((j) => matched.add(j)))));
166
- await Promise.all([...matched].filter((i) => i.match(/^\w+$/) && i.length > 3).map((i) => suggest(`${i}-`).then((i2) => i2.forEach((j) => matched.add(j)))));
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(await Promise.all([
186
- suggestSelf(processed),
187
- suggestStatic(processed),
188
- suggestUnoCache(processed),
189
- ...suggestFromPreset(processed),
190
- ...suggestVariant(processed, variants)
191
- ]), variantPrefix, variantSuffix);
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((fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)) || [];
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((fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input));
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(...uno.config.autocomplete.templates || [], ...uno.config.rulesDynamic.flatMap((i) => core.toArray(i?.[2]?.autocomplete || [])), ...uno.config.shortcuts.flatMap((i) => core.toArray(i?.[2]?.autocomplete || [])));
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(input, /\$([\w\.\|]+)/g, (m) => {
36
- parts.push({
37
- type: "theme",
38
- objects: m[1].split("|").map((i) => {
39
- return i.split(".").reduce((v, k) => {
40
- if (!k || !v[k])
41
- throw new Error(`Invalid theme key ${k}`);
42
- return v[k];
43
- }, theme);
44
- })
45
- });
46
- }, (str) => {
47
- parts.push({
48
- type: "static",
49
- value: str
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(input, /\((.*?)\)/g, (m) => {
55
- parts.push({
56
- type: "group",
57
- values: m[1].split("|").sort((a, b) => b.length - a.length)
58
- });
59
- }, (str) => {
60
- handleNonGroup(str);
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((key) => suggest(key).then((i) => i.forEach((j) => matched.add(j)))));
158
- await Promise.all([...matched].filter((i) => i.match(/^\w+$/) && i.length > 3).map((i) => suggest(`${i}-`).then((i2) => i2.forEach((j) => matched.add(j)))));
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(await Promise.all([
178
- suggestSelf(processed),
179
- suggestStatic(processed),
180
- suggestUnoCache(processed),
181
- ...suggestFromPreset(processed),
182
- ...suggestVariant(processed, variants)
183
- ]), variantPrefix, variantSuffix);
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((fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)) || [];
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((fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input));
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(...uno.config.autocomplete.templates || [], ...uno.config.rulesDynamic.flatMap((i) => toArray(i?.[2]?.autocomplete || [])), ...uno.config.shortcuts.flatMap((i) => toArray(i?.[2]?.autocomplete || [])));
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.44.7",
3
+ "version": "0.45.1",
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.10.2"
35
+ "lru-cache": "^7.13.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@unocss/core": "0.44.7"
38
+ "@unocss/core": "0.45.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "unbuild",