feat: have all emojis respect prefers-reduced-motion (#962)

This commit is contained in:
Darius Kruythoff 2023-01-16 01:51:52 +01:00 committed by GitHub
parent 97a02ef837
commit 95dda1fdb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 15 deletions

View file

@ -169,7 +169,7 @@ export function treeToText(input: Node): string {
if ('children' in input)
body = (input.children as Node[]).map(n => treeToText(n)).join('')
if (input.name === 'img') {
if (input.name === 'img' || input.name === 'picture') {
if (input.attributes.class?.includes('custom-emoji'))
return `:${input.attributes['data-emoji-id']}:`
if (input.attributes.class?.includes('iconify-emoji'))
@ -326,11 +326,34 @@ function replaceCustomEmoji(customEmojis: Record<string, mastodon.v1.CustomEmoji
if (i % 2 === 0)
return name
const emoji = customEmojis[name]
const emoji = customEmojis[name] as mastodon.v1.CustomEmoji
if (!emoji)
return `:${name}:`
return h('img', { 'src': emoji.url, 'alt': `:${name}:`, 'class': 'custom-emoji', 'data-emoji-id': name })
return h(
'picture',
{
'alt': `:${name}:`,
'class': 'custom-emoji',
'data-emoji-id': name,
},
[
h(
'source',
{
srcset: emoji.staticUrl,
media: '(prefers-reduced-motion: reduce)',
},
),
h(
'img',
{
src: emoji.url,
alt: `:${name}:`,
},
),
],
)
}).filter(Boolean)
}
}