your personal website on atproto - mirror
blento.app
1// animated emojis from
2// https://googlefonts.github.io/noto-emoji-animation/
3
4import type { CardDefinition } from '../types';
5import { listRecords, putRecord } from '$lib/atproto';
6import StatusphereCard from './StatusphereCard.svelte';
7import EditStatusphereCard from './EditStatusphereCard.svelte';
8import icons from './icons.json';
9import * as TID from '@atcute/tid';
10
11export const StatusphereCardDefinition = {
12 type: 'statusphere',
13 contentComponent: StatusphereCard,
14 editingContentComponent: EditStatusphereCard,
15
16 createNew: (item) => {
17 item.h = 3;
18 item.mobileH = 5;
19 },
20
21 loadData: async (items, { did }) => {
22 const data = await listRecords({ did, collection: 'xyz.statusphere.status', limit: 1 });
23
24 return data[0];
25 },
26 sidebarButtonText: 'Statusphere',
27
28 upload: async (item) => {
29 if (item.cardData.hasUpdate) {
30 await putRecord({
31 rkey: TID.now(),
32 collection: 'xyz.statusphere.status',
33 record: {
34 status: item.cardData.emoji,
35 createdAt: new Date().toISOString()
36 }
37 });
38 delete item.cardData.hasUpdate;
39 delete item.cardData.emoji;
40 }
41
42 return item;
43 }
44} as CardDefinition & { type: 'statusphere' };
45
46export function emojiToNotoAnimatedWebp(emoji: string | undefined): string | undefined {
47 if (!emoji) return;
48 // Convert emoji to lowercase hex codepoints joined by "-"
49 const codepoints: string[] = [];
50 for (const char of emoji) {
51 codepoints.push(char.codePointAt(0)!.toString(16).toLowerCase());
52 }
53
54 let key = codepoints.join('_');
55
56 if (icons.icons.find((v) => v.codepoint == key)) {
57 return `https://fonts.gstatic.com/s/e/notoemoji/latest/${key}/512.webp`;
58 }
59
60 key = codepoints.filter((cp) => cp !== 'fe0f' && cp !== 'fe0e').join('_');
61 if (icons.icons.find((v) => v.codepoint == key))
62 return `https://fonts.gstatic.com/s/e/notoemoji/latest/${key}/512.webp`;
63}