mirror of
https://github.com/versia-pub/frontend.git
synced 2026-03-13 03:29:16 +01:00
feat: ✨ Add emoji theme picker
This commit is contained in:
parent
ac4acd31cb
commit
6b6d1d44d2
13 changed files with 132 additions and 21 deletions
|
|
@ -3,6 +3,10 @@ import { renderToString } from "vue/server-renderer";
|
|||
import { SettingIds, type Settings } from "~/settings";
|
||||
import MentionComponent from "../components/social-elements/notes/mention.vue";
|
||||
|
||||
const emojisRegex =
|
||||
/\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?(\u200D(\p{RI}\p{RI}|\p{Emoji}(\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?))*/gu;
|
||||
const incorrectEmojisRegex = /^[#*0-9©®]$/;
|
||||
|
||||
/**
|
||||
* Takes in an HTML string, parses emojis and returns a reactive object with the parsed content.
|
||||
* @param content String of HTML content to parse
|
||||
|
|
@ -29,6 +33,7 @@ export const useParsedContent = (
|
|||
|
||||
const shouldRenderEmoji =
|
||||
toValue(settings)?.[SettingIds.CustomEmojis].value;
|
||||
const emojiFont = toValue(settings)?.[SettingIds.EmojiTheme].value;
|
||||
|
||||
// Replace emoji shortcodes with images
|
||||
if (shouldRenderEmoji) {
|
||||
|
|
@ -52,6 +57,19 @@ export const useParsedContent = (
|
|||
);
|
||||
}
|
||||
|
||||
if (emojiFont !== "native") {
|
||||
contentHtml.innerHTML = contentHtml.innerHTML.replace(
|
||||
emojisRegex,
|
||||
(match) => {
|
||||
if (incorrectEmojisRegex.test(match)) {
|
||||
return match;
|
||||
}
|
||||
|
||||
return `<img src="/emojis/${emojiFont}/${match}.svg" alt="${match}" class="h-[1em] inline not-prose hover:scale-110 transi''tion-transform duration-75 ease-in-out">`;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// Replace links containing mentions with interactive mentions
|
||||
const links = contentHtml.querySelectorAll("a");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue