your personal website on atproto - mirror blento.app
at mobile-editing 73 lines 2.1 kB view raw
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} 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}