questro
Version:
A lightweight, modular gamification library for React with unique visual components. Features combo meters, daily challenges, achievement toasts, and progress rings. Add points, badges, quests, leaderboards, levels/XP, streaks, and notifications with zero
145 lines (137 loc) • 4.61 kB
TypeScript
import * as react_jsx_runtime from 'react/jsx-runtime';
import React from 'react';
import { S as StorageAdapter } from '../types-B4P_iNGe.js';
type StreakType = 'daily' | 'weekly' | 'monthly';
type StreakConfig = {
userId: string;
type?: StreakType;
graceHours?: number;
maxFreezes?: number;
milestones?: StreakMilestone[];
onStreakUpdate?: (event: StreakUpdateEvent) => void;
onMilestoneReached?: (milestone: StreakMilestone, currentStreak: number) => void;
onStreakBroken?: (brokenStreak: number) => void;
};
type StreakMilestone = {
streak: number;
reward: {
badge?: string;
points?: number;
freeze?: number;
currency?: Record<string, number>;
};
};
type StreakEntry = {
date: string;
completed: boolean;
timestamp: number;
freezeUsed?: boolean;
};
type StreakUpdateEvent = {
previousStreak: number;
newStreak: number;
timestamp: number;
broken: boolean;
};
type StreakData = {
type: StreakType;
current: number;
longest: number;
lastActivity: number | null;
startDate: number | null;
freezes: number;
isActive: boolean;
timeUntilBreak: number;
};
type StreaksState = {
userId: string;
type: StreakType;
current: number;
longest: number;
lastActivity: number | null;
startDate: number | null;
freezes: number;
history: StreakEntry[];
milestonesReached: number[];
lastUpdated: number;
};
type CalendarDay = {
date: string;
completed: boolean;
isToday: boolean;
isFuture: boolean;
freezeUsed?: boolean;
};
type StreaksContextValue = {
streakData: StreakData;
history: StreakEntry[];
recordActivity: () => void;
useFreeze: () => boolean;
reset: () => void;
getCalendarData: (month: number, year: number) => CalendarDay[];
};
type StreaksProviderProps = {
children: React.ReactNode;
config: StreakConfig;
storage?: StorageAdapter<StreaksState>;
};
declare function StreaksProvider({ children, config, storage }: StreaksProviderProps): react_jsx_runtime.JSX.Element | null;
declare function useStreaks(): StreaksContextValue;
declare class StreaksService {
private state;
private config;
private listeners;
constructor(config: StreakConfig, initialState?: StreaksState);
private createInitialState;
getStreakData(): StreakData;
recordActivity(): void;
useFreeze(): boolean;
reset(): void;
getHistory(): StreakEntry[];
getCalendarData(month: number, year: number): Array<{
date: string;
completed: boolean;
isToday: boolean;
isFuture: boolean;
freezeUsed?: boolean;
}>;
getState(): StreaksState;
subscribe(listener: () => void): () => void;
private checkStreakStatus;
private handleStreakBroken;
private checkMilestones;
private calculateTimeUntilBreak;
private notifyListeners;
}
declare function isStreakActive(lastActivity: number | null, type: StreakType, graceHours?: number): boolean;
declare function hasActivityToday(history: StreakEntry[], type: StreakType): boolean;
declare function calculateStreak(history: StreakEntry[], type: StreakType): number;
declare function formatDate(date: Date): string;
declare function getCurrentPeriodKey(type: StreakType): string;
type StreakDisplayProps = {
showFreezes?: boolean;
showLongest?: boolean;
showWarning?: boolean;
className?: string;
children?: (data: {
current: number;
longest: number;
freezes: number;
isActive: boolean;
timeUntilBreak: number;
}) => React.ReactNode;
};
declare function StreakDisplay({ showFreezes, showLongest, showWarning, className, children, }: StreakDisplayProps): react_jsx_runtime.JSX.Element;
type StreakCalendarProps = {
month?: number;
year?: number;
className?: string;
renderDay?: (day: CalendarDay) => React.ReactNode;
children?: (data: {
days: CalendarDay[];
month: number;
year: number;
}) => React.ReactNode;
};
declare function StreakCalendar({ month, year, className, renderDay, children, }: StreakCalendarProps): react_jsx_runtime.JSX.Element;
export { type CalendarDay, StreakCalendar, type StreakCalendarProps, type StreakConfig, type StreakData, StreakDisplay, type StreakDisplayProps, type StreakEntry, type StreakMilestone, type StreakType, type StreakUpdateEvent, StreaksProvider, type StreaksProviderProps, StreaksService, type StreaksState, calculateStreak, formatDate, getCurrentPeriodKey, hasActivityToday, isStreakActive, useStreaks };