mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-11-28 06:48:36 +09:00
perf(frontend): emojilistのサイズ削減
This commit is contained in:
parent
f551b6d15e
commit
dc031b1d07
@ -71,19 +71,6 @@ const emojiDb = computed(() => {
|
||||
url: char2path(x.char),
|
||||
}));
|
||||
|
||||
for (const x of lib) {
|
||||
if (x.keywords) {
|
||||
for (const k of x.keywords) {
|
||||
unicodeEmojiDB.push({
|
||||
emoji: x.char,
|
||||
name: k,
|
||||
aliasOf: x.name,
|
||||
url: char2path(x.char),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unicodeEmojiDB.sort((a, b) => a.name.length - b.name.length);
|
||||
//#endregion
|
||||
|
||||
|
@ -232,9 +232,9 @@ watch(q, () => {
|
||||
}
|
||||
if (matches.size >= max) return matches;
|
||||
|
||||
// 名前またはエイリアスにキーワードが含まれている
|
||||
// 名前にキーワードが含まれている
|
||||
for (const emoji of emojis) {
|
||||
if (keywords.every(keyword => emoji.name.includes(keyword) || emoji.keywords.some(alias => alias.includes(keyword)))) {
|
||||
if (keywords.every(keyword => emoji.name.includes(keyword))) {
|
||||
matches.add(emoji);
|
||||
if (matches.size >= max) break;
|
||||
}
|
||||
@ -248,14 +248,6 @@ watch(q, () => {
|
||||
}
|
||||
if (matches.size >= max) return matches;
|
||||
|
||||
for (const emoji of emojis) {
|
||||
if (emoji.keywords.some(keyword => keyword.startsWith(newQ))) {
|
||||
matches.add(emoji);
|
||||
if (matches.size >= max) break;
|
||||
}
|
||||
}
|
||||
if (matches.size >= max) return matches;
|
||||
|
||||
for (const emoji of emojis) {
|
||||
if (emoji.name.includes(newQ)) {
|
||||
matches.add(emoji);
|
||||
@ -263,13 +255,6 @@ watch(q, () => {
|
||||
}
|
||||
}
|
||||
if (matches.size >= max) return matches;
|
||||
|
||||
for (const emoji of emojis) {
|
||||
if (emoji.keywords.some(keyword => keyword.includes(newQ))) {
|
||||
matches.add(emoji);
|
||||
if (matches.size >= max) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,6 @@ export const unicodeEmojiCategories = ['face', 'people', 'animals_and_nature', '
|
||||
|
||||
export type UnicodeEmojiDef = {
|
||||
name: string;
|
||||
keywords: string[];
|
||||
char: string;
|
||||
category: typeof unicodeEmojiCategories[number];
|
||||
}
|
||||
@ -10,11 +9,16 @@ export type UnicodeEmojiDef = {
|
||||
// initial converted from https://github.com/muan/emojilib/commit/242fe68be86ed6536843b83f7e32f376468b38fb
|
||||
import _emojilist from '../emojilist.json';
|
||||
|
||||
export const emojilist = _emojilist as UnicodeEmojiDef[];
|
||||
export const emojilist: UnicodeEmojiDef[] = _emojilist.map(x => ({
|
||||
name: x[1] as string,
|
||||
char: x[0] as string,
|
||||
category: unicodeEmojiCategories[x[2]],
|
||||
}));
|
||||
|
||||
const _indexByChar = new Map<string, number>();
|
||||
const _charGroupByCategory = new Map<string, string[]>();
|
||||
emojilist.forEach((emo, i) => {
|
||||
for (let i = 0; i < emojilist.length; i++) {
|
||||
const emo = emojilist[i];
|
||||
_indexByChar.set(emo.char, i);
|
||||
|
||||
if (_charGroupByCategory.has(emo.category)) {
|
||||
@ -22,7 +26,7 @@ emojilist.forEach((emo, i) => {
|
||||
} else {
|
||||
_charGroupByCategory.set(emo.category, [emo.char]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export const emojiCharByCategory = _charGroupByCategory;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user