Support non-rectangular custom emojis 😩

Platforms like Misskey have irregularly-shaped custom emojis (emojos?)

- So far this handles horizontally-wide emojis, not tall ones (haven't seen any)
- text-overflow: ellipsis is not used because it can't ellipsis-fy wide emoji images
This commit is contained in:
Lim Chee Aun 2023-09-24 15:45:01 +08:00
parent f8fc24aca4
commit d4dca0e81f
4 changed files with 32 additions and 16 deletions

View file

@ -1893,7 +1893,15 @@ function CustomEmojisModal({
}} }}
title={`:${emoji.shortcode}:`} title={`:${emoji.shortcode}:`}
> >
<picture>
{!!emoji.staticUrl && (
<source
srcset={emoji.staticUrl}
media="(prefers-reduced-motion: reduce)"
/>
)}
<img <img
class="shortcode-emoji"
src={emoji.url || emoji.staticUrl} src={emoji.url || emoji.staticUrl}
alt={emoji.shortcode} alt={emoji.shortcode}
width="16" width="16"
@ -1901,6 +1909,7 @@ function CustomEmojisModal({
loading="lazy" loading="lazy"
decoding="async" decoding="async"
/> />
</picture>
</button> </button>
))} ))}
</section> </section>

View file

@ -18,8 +18,8 @@ function EmojiText({ text, emojis }) {
src={url} src={url}
alt={word} alt={word}
class="shortcode-emoji emoji" class="shortcode-emoji emoji"
width="12" width="16"
height="12" height="16"
loading="lazy" loading="lazy"
decoding="async" decoding="async"
/> />

View file

@ -283,8 +283,8 @@
.status > .container > .meta { .status > .container > .meta {
display: flex; display: flex;
gap: 8px; gap: 4px;
justify-content: space-between; /* justify-content: space-between; */
white-space: nowrap; white-space: nowrap;
} }
.status.small > .container > .meta { .status.small > .container > .meta {
@ -293,7 +293,11 @@
.status > .container > .meta > * { .status > .container > .meta > * {
min-width: 0; min-width: 0;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; /* text-overflow: ellipsis; */
}
.status > .container > .meta .name-text {
mask-image: linear-gradient(to left, transparent, black 16px);
flex-grow: 1;
} }
.status.large > .container > .meta { .status.large > .container > .meta {
min-height: 50px; min-height: 50px;
@ -1473,10 +1477,13 @@ a.card:is(:hover, :focus):visited {
} }
.shortcode-emoji { .shortcode-emoji {
width: 1.2em; width: auto;
min-width: 1.2em;
max-width: 100%;
height: 1.2em; height: 1.2em;
vertical-align: text-bottom; vertical-align: text-bottom;
object-fit: scale-down; object-fit: cover;
object-position: left;
} }
/* EDIT HISTORY */ /* EDIT HISTORY */

View file

@ -8,7 +8,7 @@ function emojifyText(text, emojis = []) {
const { shortcode, staticUrl, url } = emoji; const { shortcode, staticUrl, url } = emoji;
text = text.replace( text = text.replace(
new RegExp(`:${shortcode}:`, 'g'), new RegExp(`:${shortcode}:`, 'g'),
`<picture><source srcset="${staticUrl}" media="(prefers-reduced-motion: reduce)"></source><img class="shortcode-emoji emoji" src="${url}" alt=":${shortcode}:" width="12" height="12" loading="lazy" decoding="async" /></picture>`, `<picture><source srcset="${staticUrl}" media="(prefers-reduced-motion: reduce)"></source><img class="shortcode-emoji emoji" src="${url}" alt=":${shortcode}:" width="16" height="16" loading="lazy" decoding="async" /></picture>`,
); );
}); });
// console.log(text, emojis); // console.log(text, emojis);