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 upload: async (item) => {
27 if (item.cardData.hasUpdate) {
28 await putRecord({
29 rkey: TID.now(),
30 collection: 'xyz.statusphere.status',
31 record: {
32 status: item.cardData.emoji,
33 createdAt: new Date().toISOString()
34 }
35 });
36 delete item.cardData.hasUpdate;
37 // Keep item.cardData.emoji so each card can have its own status
38 }
39
40 return item;
41 },
42
43 migrate: (item) => {
44 if (item.cardData.title && !item.cardData.label) {
45 item.cardData.label = item.cardData.title;
46 }
47 },
48 canHaveLabel: true,
49
50 name: 'Emoji',
51 keywords: ['status', 'mood', 'reaction', 'statusphere'],
52 groups: ['Media'],
53 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>`
54} as CardDefinition & { type: 'statusphere' };
55
56export function emojiToNotoAnimatedWebp(emoji: string | undefined): string | undefined {
57 if (!emoji) return;
58 // Convert emoji to lowercase hex codepoints joined by "-"
59 const codepoints: string[] = [];
60 for (const char of emoji) {
61 codepoints.push(char.codePointAt(0)!.toString(16).toLowerCase());
62 }
63
64 let key = codepoints.join('_');
65
66 if (icons.icons.find((v) => v.codepoint == key)) {
67 return `https://fonts.gstatic.com/s/e/notoemoji/latest/${key}/512.webp`;
68 }
69
70 key = codepoints.filter((cp) => cp !== 'fe0f' && cp !== 'fe0e').join('_');
71 if (icons.icons.find((v) => v.codepoint == key))
72 return `https://fonts.gstatic.com/s/e/notoemoji/latest/${key}/512.webp`;
73}