hermes-kanban-miniapp/frontend/src/telegram.ts

32 lines
824 B
TypeScript
Raw Normal View History

2026-07-09 17:19:33 +03:00
declare global {
interface Window {
Telegram?: {
WebApp?: {
ready?: () => void
expand?: () => void
initData?: string
colorScheme?: 'light' | 'dark'
themeParams?: Record<string, string>
}
}
}
}
export function getTelegramInitData(): string | undefined {
return window.Telegram?.WebApp?.initData || undefined
}
export function applyTelegramTheme(): void {
const webApp = window.Telegram?.WebApp
webApp?.ready?.()
webApp?.expand?.()
const theme = webApp?.themeParams || {}
const root = document.documentElement
Object.entries(theme).forEach(([key, value]) => {
if (typeof value === 'string') root.style.setProperty(`--tg-${key.replaceAll('_', '-')}`, value)
})
if (webApp?.colorScheme) root.dataset.theme = webApp.colorScheme
}
export {}