mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Improve emoji picker performance (#84)
* Improved performance on the Unicode Search page: - Created new flexSearch component (Faster than fuzzySearch). For more information, see https://github.com/nextapps-de/flexsearch - Replaced fuzzySearch with the flexSearch component on the unicode search page - Fixed a bug where the search limit counter didn't have any effect - Reduced the default search limit from 100 to 40 to reduce lag from loading all the ui elements * Added clarification to comment * components.d.ts update * - Replaced FuzzySearch with FlexSearch on the ISO 3166 Searcher page - Reduced the debounce from 500ms to 250ms - Reduced the default search limit from 100 to 20, and fixed a bug where the search limit wasn't applied when the value changed - Added the `readonly` prop to the `input-copyable` field - Added the `readonly` flag to all input copyable fields on the unicode search and iso 3166 searcher pages * Merged new changes to flexSearch * chore: vercel optimisation tentative * Emoji Picker: - Replaced fuzzysearch with flexsearch - Reduced debounce from 500ms to 250ms - Increased search limit from 100 to 150 - Implemented a UI loading sequence where it will load an emoji group each 150ms instead of loading all groups at once. This eliminates the lag experienced when loading the page or when removing the search query - Updated unicode-emoji-json from version 0.4.0 to 0.8.0 Emoji Card: - Fixed an issue where the country flag emojis weren't being rendered - Added row which displays the emoji keywords, and uses a tooltip to display all keywords when they are truncated to fit in the card - Moved codepoints and unicode escape lines to seperate rows instead of occasionally being displayed on the same line * - Added logic to use an emoji in the search query * small change --------- Co-authored-by: ShareVB <sharevb@gmail.com>
This commit is contained in:
1 parent
eb401042a6
commit
3ed3f90ee7
8 files changed
+421
-73
No files matched your search
@@ -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
|
||||
}
|
||||
}
|
||||
Vendored
+2
@@ -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']
|
||||
|
||||
+2
-2
@@ -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",
|
||||
|
||||
Generated
+8
-8
@@ -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:
|
||||
|
||||
@@ -1,42 +1,203 @@
|
||||
<script setup lang="ts">
|
||||
import type { EmojiInfo } from './emoji.types';
|
||||
import { getAllCodePoints, isEmojiSupported } from './emoji-utils';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const props = (defineProps<{ emojiInfo: EmojiInfo }>());
|
||||
const props = defineProps<{ emojiInfo: EmojiInfo }>();
|
||||
const { emojiInfo } = toRefs(props);
|
||||
|
||||
const { copy } = useCopy();
|
||||
|
||||
// Check if emoji is properly supported
|
||||
const emojiSupported = computed(() => isEmojiSupported(emojiInfo.value.emoji));
|
||||
|
||||
// Get complete code point information
|
||||
const completeCodePoints = computed(() => getAllCodePoints(emojiInfo.value.emoji));
|
||||
|
||||
// Check if keywords are truncated
|
||||
const keywordsEl = ref<HTMLElement>();
|
||||
const isKeywordsTruncated = computed(() => {
|
||||
if (!keywordsEl.value) {
|
||||
return false;
|
||||
}
|
||||
return keywordsEl.value.scrollWidth > keywordsEl.value.clientWidth;
|
||||
});
|
||||
|
||||
// Copy functions with better notifications
|
||||
async function copyEmoji() {
|
||||
await copy(emojiInfo.value.emoji, {
|
||||
notificationMessage: `Emoji ${emojiInfo.value.emoji} copied to clipboard`,
|
||||
});
|
||||
}
|
||||
|
||||
async function copyCodePoints() {
|
||||
await copy(completeCodePoints.value, {
|
||||
notificationMessage: `Code points '${completeCodePoints.value}' copied to clipboard`,
|
||||
});
|
||||
}
|
||||
|
||||
async function copyUnicode() {
|
||||
await copy(emojiInfo.value.unicode, {
|
||||
notificationMessage: `Unicode '${emojiInfo.value.unicode}' copied to clipboard`,
|
||||
});
|
||||
}
|
||||
|
||||
async function copyName() {
|
||||
await copy(emojiInfo.value.title, {
|
||||
notificationMessage: `Name '${emojiInfo.value.title}' copied to clipboard`,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card flex items-center gap-3 important:py-8px important:pl-10px important:pr-5px>
|
||||
<div cursor-pointer text-30px @click="copy(emojiInfo.emoji, { notificationMessage: `Emoji ${emojiInfo.emoji} copied to the clipboard` })">
|
||||
<c-card
|
||||
:class="{ 'emoji-unsupported': !emojiSupported }"
|
||||
flex
|
||||
items-center
|
||||
gap-3
|
||||
transition-all
|
||||
important:py-8px
|
||||
important:pl-10px
|
||||
important:pr-5px
|
||||
hover:shadow-md
|
||||
>
|
||||
<!-- Emoji Display -->
|
||||
<div
|
||||
cursor-pointer
|
||||
text-30px
|
||||
class="emoji-display"
|
||||
:class="{
|
||||
'emoji-fallback': !emojiSupported,
|
||||
'emoji-supported': emojiSupported,
|
||||
}"
|
||||
:title="`Click to copy ${emojiInfo.emoji}`"
|
||||
@click="copyEmoji"
|
||||
>
|
||||
{{ emojiInfo.emoji }}
|
||||
</div>
|
||||
|
||||
<!-- Emoji Information -->
|
||||
<div min-w-0 flex-1>
|
||||
<div truncate font-bold>
|
||||
<!-- Title (clickable to copy name) -->
|
||||
<div
|
||||
cursor-pointer
|
||||
truncate
|
||||
font-bold
|
||||
transition
|
||||
hover:text-primary
|
||||
:title="`Click to copy name: ${emojiInfo.title}`"
|
||||
@click="copyName"
|
||||
>
|
||||
{{ emojiInfo.title }}
|
||||
</div>
|
||||
|
||||
<!-- <div>
|
||||
<c-link>
|
||||
{{ emojiInfo.codePoints }}
|
||||
</c-link>
|
||||
<!-- Keywords (if available) -->
|
||||
<div
|
||||
v-if="emojiInfo.keywords && emojiInfo.keywords.length > 0"
|
||||
ref="keywordsEl"
|
||||
mb-1
|
||||
truncate
|
||||
text-xs
|
||||
op-60
|
||||
:title="isKeywordsTruncated ? emojiInfo.keywords.join(', ') : undefined"
|
||||
>
|
||||
{{ emojiInfo.keywords.join(', ') }}
|
||||
</div>
|
||||
<div />
|
||||
<div rounded op-70>
|
||||
Unicode: <span border="1px solid current op-30" b-rd-xl px-12px py-4px>{{ emojiInfo.unicode }}</span>
|
||||
</div> -->
|
||||
|
||||
<div flex gap-2 text-xs font-mono op-70>
|
||||
<span cursor-pointer transition hover:text-primary @click="copy(emojiInfo.codePoints, { notificationMessage: `Code points '${emojiInfo.codePoints}' copied to the clipboard` })">
|
||||
{{ emojiInfo.codePoints }}
|
||||
<!-- Code Points and Unicode -->
|
||||
<div flex flex-col text-xs font-mono op-70>
|
||||
<!-- Code Points -->
|
||||
<span
|
||||
cursor-pointer
|
||||
truncate
|
||||
px-1
|
||||
py-0.25
|
||||
transition
|
||||
hover:bg-gray-100
|
||||
hover:text-primary
|
||||
hover:op-100
|
||||
dark:hover:bg-gray-800
|
||||
:title="`Click to copy: ${completeCodePoints}`"
|
||||
@click="copyCodePoints"
|
||||
>
|
||||
{{ completeCodePoints }}
|
||||
</span>
|
||||
<span cursor-pointer truncate transition hover:text-primary @click="copy(emojiInfo.unicode, { notificationMessage: `Unicode '${emojiInfo.unicode}' copied to the clipboard` })">
|
||||
|
||||
<!-- Unicode Escape -->
|
||||
<span
|
||||
cursor-pointer
|
||||
truncate
|
||||
rounded
|
||||
px-1
|
||||
py-0.25
|
||||
transition
|
||||
hover:bg-gray-100
|
||||
hover:text-primary
|
||||
hover:op-100
|
||||
dark:hover:bg-gray-800
|
||||
:title="`Click to copy: ${emojiInfo.unicode}`"
|
||||
@click="copyUnicode"
|
||||
>
|
||||
{{ emojiInfo.unicode }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Support indicator -->
|
||||
<div v-if="!emojiSupported" text-xs op-50 title="This emoji might not display correctly on your system">
|
||||
⚠️
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.emoji-display {
|
||||
font-family:
|
||||
'Noto Color Emoji', /* Best flag and complex emoji support */
|
||||
'Apple Color Emoji', /* Apple devices */
|
||||
'Segoe UI Emoji', /* Windows */
|
||||
'Twemoji Mozilla', /* Firefox fallback */
|
||||
'EmojiOne Color', /* Additional fallback */
|
||||
sans-serif;
|
||||
font-feature-settings: 'liga' off;
|
||||
font-variant-emoji: emoji;
|
||||
text-rendering: optimizeQuality;
|
||||
line-height: 1;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.emoji-display:hover {
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.emoji-supported {
|
||||
/* Additional styles for well-supported emojis */
|
||||
filter: none;
|
||||
}
|
||||
|
||||
.emoji-fallback {
|
||||
/* Styling for potentially unsupported emojis */
|
||||
background-color: rgba(128, 128, 128, 0.1);
|
||||
border-radius: 4px;
|
||||
padding: 2px 4px;
|
||||
border: 1px dashed rgba(128, 128, 128, 0.3);
|
||||
}
|
||||
|
||||
.emoji-unsupported {
|
||||
opacity: 0.8;
|
||||
border-left: 3px solid orange;
|
||||
}
|
||||
|
||||
/* Hover effects for interactive elements */
|
||||
.emoji-display,
|
||||
[title*='Click to copy'] {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* Better responsive design */
|
||||
@media (max-width: 640px) {
|
||||
.emoji-display {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -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();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div mx-auto max-w-2400px important:flex-1>
|
||||
<div mx-auto max-w-600px flex justify-center gap-3>
|
||||
<div mx-auto mb-4 max-w-600px flex justify-center gap-3>
|
||||
<c-input-text
|
||||
v-model:value="searchQuery"
|
||||
placeholder="Search emojis (e.g. 'smile')..."
|
||||
v-model:value="rawSearchQuery"
|
||||
placeholder="Search emojis (e.g. 'smile') or paste an emoji (e.g. '😄')"
|
||||
class="flex-1"
|
||||
>
|
||||
<template #prefix>
|
||||
<icon-mdi-search mr-6px color-black op-70 dark:color-white />
|
||||
</template>
|
||||
</c-input-text>
|
||||
<n-form-item label="Max results:" label-placement="left">
|
||||
<n-input-number v-model:value="limit" :min="1" />
|
||||
<n-input-number v-model:value="limit" :min="10" :max="500" :step="10" style="width: 100px" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<!-- Search Results -->
|
||||
<div v-if="searchQuery.trim().length > 0">
|
||||
<div
|
||||
v-if="searchResult.length === 0"
|
||||
mt-4
|
||||
text-20px
|
||||
font-bold
|
||||
>
|
||||
No results
|
||||
<div v-if="displayedSearchResults.length === 0" mt-4 text-center text-20px font-bold op-70>
|
||||
<div>No results found</div>
|
||||
<div mt-2 text-14px font-normal>
|
||||
Try searching for something else like "smile", "flag", or "😄"
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div mt-4 text-20px font-bold>
|
||||
Search result
|
||||
<div mb-3 mt-4 flex items-center gap-2 text-20px font-bold>
|
||||
<span>Search Results</span>
|
||||
<span text-14px font-normal op-70>({{ displayedSearchResults.length }} found)</span>
|
||||
</div>
|
||||
|
||||
<emoji-grid :emoji-infos="searchResult" />
|
||||
<emoji-grid :emoji-infos="displayedSearchResults" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-for="{ group, emojiInfos } in emojisGroups"
|
||||
v-else
|
||||
:key="group"
|
||||
>
|
||||
<div mt-4 text-20px font-bold>
|
||||
{{ group }}
|
||||
<!-- All Emojis by Groups (Auto-loaded) -->
|
||||
<div v-else>
|
||||
<div v-for="{ group, emojiInfos } in visibleEmojisGroups" :key="group" mb-6>
|
||||
<div mb-3 mt-4 flex items-center gap-2 text-20px font-bold>
|
||||
<span>{{ group }}</span>
|
||||
<span text-14px font-normal op-70>({{ emojiInfos.length }})</span>
|
||||
</div>
|
||||
|
||||
<emoji-grid :emoji-infos="emojiInfos" />
|
||||
</div>
|
||||
|
||||
<emoji-grid :emoji-infos="emojiInfos" />
|
||||
<!-- Loading indicator when more groups are coming -->
|
||||
<div v-if="visibleGroupsCount < emojisGroups.length" mt-6 text-center>
|
||||
<div text-14px op-70>
|
||||
Loading more groups... ({{ visibleGroupsCount }}/{{ emojisGroups.length }})
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user