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 // Keep item.cardData.emoji so each card can have its own status
40 }
41
42 return item;
43 },
44
45 migrate: (item) => {
46 if (item.cardData.title && !item.cardData.label) {
47 item.cardData.label = item.cardData.title;
48 }
49 },
50 canHaveLabel: true,
51
52 name: 'Emoji',
53 groups: ['Media'],
54 icon: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="size-4"><path stroke-linecap="round" stroke-linejoin="round" d="M15.182 15.182a4.5 4.5 0 0 1-6.364 0M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0ZM9.75 9.75c0 .414-.168.75-.375.75S9 10.164 9 9.75 9.168 9 9.375 9s.375.336.375.75Zm-.375 0h.008v.015h-.008V9.75Zm5.625 0c0 .414-.168.75-.375.75s-.375-.336-.375-.75.168-.75.375-.75.375.336.375.75Zm-.375 0h.008v.015h-.008V9.75Z" /></svg>`
55
56} as CardDefinition & { type: 'statusphere' };
57
58export function emojiToNotoAnimatedWebp(emoji: string | undefined): string | undefined {
59 if (!emoji) return;
60 // Convert emoji to lowercase hex codepoints joined by "-"
61 const codepoints: string[] = [];
62 for (const char of emoji) {
63 codepoints.push(char.codePointAt(0)!.toString(16).toLowerCase());
64 }
65
66 let key = codepoints.join('_');
67
68 if (icons.icons.find((v) => v.codepoint == key)) {
69 return `https://fonts.gstatic.com/s/e/notoemoji/latest/${key}/512.webp`;
70 }
71
72 key = codepoints.filter((cp) => cp !== 'fe0f' && cp !== 'fe0e').join('_');
73 if (icons.icons.find((v) => v.codepoint == key))
74 return `https://fonts.gstatic.com/s/e/notoemoji/latest/${key}/512.webp`;
75}