@unocss/autocomplete 0.35.0 → 0.35.3

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
@@ -142,7 +142,7 @@ function searchUsageBoundary(line, index) {
142
142
 
143
143
  function createAutocomplete(uno) {
144
144
  const templateCache = /* @__PURE__ */ new Map();
145
- const cache = new LRU__default({ max: 1e3 });
145
+ const cache = new LRU__default({ max: 5e3 });
146
146
  let staticUtils = [];
147
147
  const templates = [];
148
148
  reset();
@@ -177,14 +177,15 @@ function createAutocomplete(uno) {
177
177
  if (cache.has(input))
178
178
  return cache.get(input);
179
179
  const [, processed, , variants] = uno.matchVariants(input);
180
- const idx = processed ? input.search(core.escapeRegExp(processed)) : input.length;
180
+ let idx = processed ? input.search(core.escapeRegExp(processed)) : input.length;
181
181
  if (idx === -1)
182
- return [];
182
+ idx = 0;
183
183
  const variantPrefix = input.slice(0, idx);
184
184
  const variantSuffix = input.slice(idx + input.length);
185
185
  const result = processSuggestions(await Promise.all([
186
186
  suggestSelf(processed),
187
187
  suggestStatic(processed),
188
+ suggestUnoCache(processed),
188
189
  ...suggestFromPreset(processed),
189
190
  ...suggestVariant(processed, variants)
190
191
  ]), variantPrefix, variantSuffix);
@@ -229,6 +230,10 @@ function createAutocomplete(uno) {
229
230
  async function suggestStatic(input) {
230
231
  return staticUtils.filter((i) => i.startsWith(input));
231
232
  }
233
+ async function suggestUnoCache(input) {
234
+ const keys = Array.from(uno._cache.entries());
235
+ return keys.filter((i) => i[1] && i[0].startsWith(input)).map((i) => i[0]);
236
+ }
232
237
  function suggestFromPreset(input) {
233
238
  return templates.map((fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)) || [];
234
239
  }
@@ -238,9 +243,12 @@ function createAutocomplete(uno) {
238
243
  function reset() {
239
244
  templateCache.clear();
240
245
  cache.clear();
241
- staticUtils = Object.keys(uno.config.rulesStaticMap);
246
+ staticUtils = [
247
+ ...Object.keys(uno.config.rulesStaticMap),
248
+ ...uno.config.shortcuts.filter((i) => typeof i[0] === "string").map((i) => i[0])
249
+ ];
242
250
  templates.length = 0;
243
- templates.push(...uno.config.autocomplete.templates || [], ...uno.config.rulesDynamic.flatMap((i) => core.toArray(i?.[2]?.autocomplete || [])));
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 || [])));
244
252
  }
245
253
  function processSuggestions(suggestions, prefix = "", suffix = "") {
246
254
  return core.uniq(suggestions.flat()).filter((i) => !!(i && !i.match(/-$/))).sort((a, b) => {
package/dist/index.mjs CHANGED
@@ -134,7 +134,7 @@ function searchUsageBoundary(line, index) {
134
134
 
135
135
  function createAutocomplete(uno) {
136
136
  const templateCache = /* @__PURE__ */ new Map();
137
- const cache = new LRU({ max: 1e3 });
137
+ const cache = new LRU({ max: 5e3 });
138
138
  let staticUtils = [];
139
139
  const templates = [];
140
140
  reset();
@@ -169,14 +169,15 @@ function createAutocomplete(uno) {
169
169
  if (cache.has(input))
170
170
  return cache.get(input);
171
171
  const [, processed, , variants] = uno.matchVariants(input);
172
- const idx = processed ? input.search(escapeRegExp(processed)) : input.length;
172
+ let idx = processed ? input.search(escapeRegExp(processed)) : input.length;
173
173
  if (idx === -1)
174
- return [];
174
+ idx = 0;
175
175
  const variantPrefix = input.slice(0, idx);
176
176
  const variantSuffix = input.slice(idx + input.length);
177
177
  const result = processSuggestions(await Promise.all([
178
178
  suggestSelf(processed),
179
179
  suggestStatic(processed),
180
+ suggestUnoCache(processed),
180
181
  ...suggestFromPreset(processed),
181
182
  ...suggestVariant(processed, variants)
182
183
  ]), variantPrefix, variantSuffix);
@@ -221,6 +222,10 @@ function createAutocomplete(uno) {
221
222
  async function suggestStatic(input) {
222
223
  return staticUtils.filter((i) => i.startsWith(input));
223
224
  }
225
+ async function suggestUnoCache(input) {
226
+ const keys = Array.from(uno._cache.entries());
227
+ return keys.filter((i) => i[1] && i[0].startsWith(input)).map((i) => i[0]);
228
+ }
224
229
  function suggestFromPreset(input) {
225
230
  return templates.map((fn) => typeof fn === "function" ? fn(input) : getParsed(fn)(input)) || [];
226
231
  }
@@ -230,9 +235,12 @@ function createAutocomplete(uno) {
230
235
  function reset() {
231
236
  templateCache.clear();
232
237
  cache.clear();
233
- staticUtils = Object.keys(uno.config.rulesStaticMap);
238
+ staticUtils = [
239
+ ...Object.keys(uno.config.rulesStaticMap),
240
+ ...uno.config.shortcuts.filter((i) => typeof i[0] === "string").map((i) => i[0])
241
+ ];
234
242
  templates.length = 0;
235
- templates.push(...uno.config.autocomplete.templates || [], ...uno.config.rulesDynamic.flatMap((i) => toArray(i?.[2]?.autocomplete || [])));
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 || [])));
236
244
  }
237
245
  function processSuggestions(suggestions, prefix = "", suffix = "") {
238
246
  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.35.0",
3
+ "version": "0.35.3",
4
4
  "description": "Autocomplete utils for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -21,8 +21,8 @@
21
21
  "sideEffects": false,
22
22
  "exports": {
23
23
  ".": {
24
- "import": "./dist/index.mjs",
25
- "require": "./dist/index.cjs"
24
+ "require": "./dist/index.cjs",
25
+ "import": "./dist/index.mjs"
26
26
  }
27
27
  },
28
28
  "main": "./dist/index.cjs",
@@ -35,7 +35,7 @@
35
35
  "lru-cache": "^7.10.1"
36
36
  },
37
37
  "devDependencies": {
38
- "@unocss/core": "0.35.0"
38
+ "@unocss/core": "0.35.3"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "unbuild",