diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index d4fd5aac..65c56a65 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -39,6 +39,7 @@ "h": true, "ignorableWatch": true, "inject": true, + "injectLocal": true, "isDefined": true, "isProxy": true, "isReactive": true, @@ -68,6 +69,7 @@ "onUpdated": true, "pausableWatch": true, "provide": true, + "provideLocal": true, "reactify": true, "reactifyObject": true, "reactive": true, @@ -96,6 +98,7 @@ "toReactive": true, "toRef": true, "toRefs": true, + "toValue": true, "triggerRef": true, "tryOnBeforeMount": true, "tryOnBeforeUnmount": true, @@ -130,6 +133,7 @@ "useBrowserLocation": true, "useCached": true, "useClipboard": true, + "useClipboardItems": true, "useCloned": true, "useColorMode": true, "useConfirmDialog": true, @@ -285,10 +289,6 @@ "watchThrottled": true, "watchTriggerable": true, "watchWithFilter": true, - "whenever": true, - "toValue": true, - "injectLocal": true, - "provideLocal": true, - "useClipboardItems": true + "whenever": true } } diff --git a/components.d.ts b/components.d.ts index b1530c30..da900b88 100644 --- a/components.d.ts +++ b/components.d.ts @@ -303,6 +303,7 @@ declare module '@vue/runtime-core' { NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default'] 'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default'] NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default'] + NButton: typeof import('naive-ui')['NButton'] NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NEllipsis: typeof import('naive-ui')['NEllipsis'] @@ -318,6 +319,7 @@ declare module '@vue/runtime-core' { NLayoutSider: typeof import('naive-ui')['NLayoutSider'] NMenu: typeof import('naive-ui')['NMenu'] NP: typeof import('naive-ui')['NP'] + NSpin: typeof import('naive-ui')['NSpin'] NTable: typeof import('naive-ui')['NTable'] NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default'] NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] diff --git a/package.json b/package.json index ed83b2fa..f547f4c4 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "duration-fns": "^3.0.2", "email-bounce-parser-browser": "^1.1.0", "email-normalizer": "^1.0.0", - "emojilib": "^4.0.1", + "emojilib": "^4.0.2", "event-cron-parser": "^1.0.35", "exif-be-gone": "^1.5.1", "exifreader": "^4.26.1", @@ -268,7 +268,7 @@ "turndown": "^7.2.0", "ua-parser-js": "^2.0.1", "ulid": "^2.3.0", - "unicode-emoji-json": "^0.4.0", + "unicode-emoji-json": "^0.8.0", "unique-random": "^4.0.0", "unixcrypt-browser": "^2.0.4", "unplugin-auto-import": "^0.16.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b158c6c..290bd6c7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -273,8 +273,8 @@ dependencies: specifier: ^1.0.0 version: 1.0.0 emojilib: - specifier: ^4.0.1 - version: 4.0.1 + specifier: ^4.0.2 + version: 4.0.2 event-cron-parser: specifier: ^1.0.35 version: 1.0.35 @@ -702,8 +702,8 @@ dependencies: specifier: ^2.3.0 version: 2.3.0 unicode-emoji-json: - specifier: ^0.4.0 - version: 0.4.0 + specifier: ^0.8.0 + version: 0.8.0 unique-random: specifier: ^4.0.0 version: 4.0.0 @@ -10170,8 +10170,8 @@ packages: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} dev: false - /emojilib@4.0.1: - resolution: {integrity: sha512-zVY5JGxycujUimHkBn2lg5NCVwASJiQA2fhKfDPgyDFmNTftiw6KdOcq2fQt1HCVw0YeYW/ccYxQHQNjZpNeuw==} + /emojilib@4.0.2: + resolution: {integrity: sha512-8sP3sfAi861cNaFFp7RmyKi4S26K34ZKy4si75ojUW627AIVBHhMSu2SFJo3YRoK66YWnbysIbOk/d48uEqtKQ==} dev: false /encoding-japanese@2.2.0: @@ -17596,8 +17596,8 @@ packages: engines: {node: '>=4'} dev: true - /unicode-emoji-json@0.4.0: - resolution: {integrity: sha512-lVNOwh2AnmbwqtSrEVjAWKQoVzWgyWmXVqPuPkPfKb0tnA0+uYN/4ILCTdy9IRj/+3drAVhmjwjNJQr2dhCwnA==} + /unicode-emoji-json@0.8.0: + resolution: {integrity: sha512-3wDXXvp6YGoKGhS2O2H7+V+bYduOBydN1lnI0uVfr1cIdY02uFFiEH1i3kE5CCE4l6UqbLKVmEFW9USxTAMD1g==} dev: false /unicode-match-property-ecmascript@2.0.0: diff --git a/src/tools/emoji-picker/emoji-card.vue b/src/tools/emoji-picker/emoji-card.vue index e2977862..cb4e29f2 100644 --- a/src/tools/emoji-picker/emoji-card.vue +++ b/src/tools/emoji-picker/emoji-card.vue @@ -1,42 +1,203 @@ + + diff --git a/src/tools/emoji-picker/emoji-picker.vue b/src/tools/emoji-picker/emoji-picker.vue index f245635d..ca9571a7 100644 --- a/src/tools/emoji-picker/emoji-picker.vue +++ b/src/tools/emoji-picker/emoji-picker.vue @@ -3,12 +3,55 @@ import emojiUnicodeData from 'unicode-emoji-json'; import emojiKeywords from 'emojilib'; import _ from 'lodash'; import type { EmojiInfo } from './emoji.types'; -import { useFuzzySearch } from '@/composable/fuzzySearch'; +import { escapeUnicodeComplete, getAllCodePoints } from './emoji-utils'; import useDebouncedRef from '@/composable/debouncedref'; +import { useFlexSearch } from '@/composable/flexSearch'; -const escapeUnicode = ({ emoji }: { emoji: string }) => emoji.split('').map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, '0')}`).join(''); -const getEmojiCodePoints = ({ emoji }: { emoji: string }) => emoji.codePointAt(0) ? `0x${emoji.codePointAt(0)?.toString(16)}` : undefined; +// Enhanced emoji processing functions +const escapeUnicode = ({ emoji }: { emoji: string }) => escapeUnicodeComplete(emoji); +function getEmojiCodePoints({ emoji }: { emoji: string }) { + // Get all code points for complex emojis (like flags) + const codePoints: string[] = []; + for (const char of emoji) { + const codePoint = char.codePointAt(0); + if (codePoint) { + codePoints.push(`0x${codePoint.toString(16)}`); + } + } + return codePoints.length > 0 ? codePoints.join(' ') : undefined; +} + +// Function to detect if a string contains emojis +function containsEmoji(text: string): boolean { + // Check each character in the text against our emoji data + for (const char of text) { + if (emojiUnicodeData[char]) { + return true; + } + } + return false; +} +// Function to convert emojis in text to their unicode representations +function convertEmojisToUnicode(text: string): string { + let result = text; + + // Process each character/emoji in the string + for (const char of text) { + // Check if this character is an emoji by looking it up in our emoji data + if (emojiUnicodeData[char]) { + const unicodeString = escapeUnicode({ emoji: char }); + if (unicodeString) { + // Replace the emoji with its unicode representation + result = result.replace(char, unicodeString); + } + } + } + + return result; +} + +// Process emojis with enhanced code point handling const emojis = _.map(emojiUnicodeData, (emojiInfo, emoji) => ({ ...emojiInfo, emoji, @@ -16,75 +59,167 @@ const emojis = _.map(emojiUnicodeData, (emojiInfo, emoji) => ({ keywords: emojiKeywords[emoji as keyof typeof emojiKeywords], codePoints: getEmojiCodePoints({ emoji }), unicode: escapeUnicode({ emoji }), + allCodePoints: getAllCodePoints(emoji), // Add complete code point info })); -const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _ - .chain(emojis) +// Group emojis and sort groups for better organization +const emojisGroups: { emojiInfos: EmojiInfo[]; group: string }[] = _.chain(emojis) .groupBy('group') - .map((emojiInfos, group) => ({ group, emojiInfos })) + .map((emojiInfos, group) => ({ + group: _.startCase(group), // Better group name formatting + emojiInfos, + })) .value(); -const limit = ref(100); -const searchQuery = useDebouncedRef('', 500); +const limit = ref(150); +const rawSearchQuery = ref(''); +const searchQuery = useDebouncedRef('', 250); -const { searchResult } = useFuzzySearch({ +// Add automated lazy loading for emoji groups +const visibleGroupsCount = ref(1); // Start with 1 group +let loadingInterval: NodeJS.Timeout | null = null; + +// Watch for raw search query changes and process emojis +watch(rawSearchQuery, (newQuery) => { + if (containsEmoji(newQuery)) { + // Convert emojis to unicode and update the debounced search query + const unicodeQuery = convertEmojisToUnicode(newQuery); + searchQuery.value = unicodeQuery; + } + else { + // Regular text search + searchQuery.value = newQuery; + } +}); + +const { searchResult } = useFlexSearch({ search: searchQuery, data: emojis, options: { - keys: ['group', { name: 'name', weight: 3 }, 'keywords', 'unicode', 'codePoints', 'emoji'], - threshold: 0.3, - useExtendedSearch: true, - isCaseSensitive: false, + keys: ['group', { name: 'name', weight: 3 }, 'keywords', 'unicode', 'codePoints', 'allCodePoints', 'emoji'], + filterEmpty: false, }, - limit: limit.value, + limit, +}); + +// Computed property for filtered results +const displayedSearchResults = computed(() => { + return searchResult.value.slice(0, limit.value); +}); + +// Computed property for visible emoji groups +const visibleEmojisGroups = computed(() => { + return emojisGroups.slice(0, visibleGroupsCount.value); +}); + +// Function to stop automated loading +function stopAutomatedLoading() { + if (loadingInterval) { + clearInterval(loadingInterval); + loadingInterval = null; + } +} + +// Function to start automated loading +function startAutomatedLoading() { + // Clear any existing interval + if (loadingInterval) { + clearInterval(loadingInterval); + } + + // Start loading groups every 150ms + loadingInterval = setInterval(() => { + if (visibleGroupsCount.value < emojisGroups.length) { + visibleGroupsCount.value++; + } + else { + // Stop loading when all groups are visible + stopAutomatedLoading(); + } + }, 150); +} + +// Watch for search query changes +watch(searchQuery, (newQuery, oldQuery) => { + if (newQuery.trim()) { + // Stop automated loading when searching + stopAutomatedLoading(); + } + else if (oldQuery && oldQuery.trim()) { + // Reset and start automated loading when switching from search to browse + visibleGroupsCount.value = 1; + nextTick(() => { + startAutomatedLoading(); + }); + } +}); + +// Start automated loading on component mount (when not searching) +onMounted(() => { + if (!searchQuery.value.trim()) { + startAutomatedLoading(); + } +}); + +// Clean up on component unmount +onUnmounted(() => { + stopAutomatedLoading(); }); diff --git a/src/tools/emoji-picker/emoji-utils.ts b/src/tools/emoji-picker/emoji-utils.ts new file mode 100644 index 00000000..e52630ee --- /dev/null +++ b/src/tools/emoji-picker/emoji-utils.ts @@ -0,0 +1,48 @@ +export function getAllCodePoints(emoji: string): string { + const codePoints: string[] = []; + for (const char of emoji) { + const codePoint = char.codePointAt(0); + if (codePoint) { + codePoints.push(`U+${codePoint.toString(16).toUpperCase().padStart(4, '0')}`); + } + } + return codePoints.join(' '); +} + +export function escapeUnicodeComplete(emoji: string): string { + return Array.from(emoji) + .map((char) => { + const codePoint = char.codePointAt(0); + return codePoint ? `\\u${codePoint.toString(16).padStart(4, '0')}` : ''; + }) + .join(''); +} + +export function isEmojiSupported(emoji: string): boolean { + if (typeof document === 'undefined') { + return true; + } // SSR fallback + + const canvas = document.createElement('canvas'); + const ctx = canvas.getContext('2d'); + if (!ctx) { + return true; + } + + canvas.width = 32; + canvas.height = 32; + ctx.textBaseline = 'top'; + ctx.font = '24px "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji"'; + + const beforeImageData = ctx.getImageData(0, 0, 32, 32).data; + ctx.fillText(emoji, 0, 0); + const afterImageData = ctx.getImageData(0, 0, 32, 32).data; + + // Check if any pixels changed + for (let i = 0; i < beforeImageData.length; i++) { + if (beforeImageData[i] !== afterImageData[i]) { + return true; + } + } + return false; +} diff --git a/src/tools/emoji-picker/emoji.types.ts b/src/tools/emoji-picker/emoji.types.ts index 7b7bf922..d2038eb0 100644 --- a/src/tools/emoji-picker/emoji.types.ts +++ b/src/tools/emoji-picker/emoji.types.ts @@ -1,8 +1,10 @@ -import type emojiUnicodeData from 'unicode-emoji-json'; - -export type EmojiInfo = { - title: string +export interface EmojiInfo { emoji: string - codePoints: string | undefined + name: string + title: string + group: string + keywords?: string[] + codePoints?: string unicode: string -} & typeof emojiUnicodeData[string]; + allCodePoints?: string +}