feat: implement Figlet, Pastel, and Unit tools with a unified layout
- Add Figlet text converter with font selection and history - Add Pastel color palette generator and manipulation suite - Add comprehensive Units converter with category-based logic - Introduce AppShell with Sidebar and Header for navigation - Modernize theme system with CSS variables and new animations - Update project configuration and dependencies
This commit is contained in:
70
lib/storage/favorites.ts
Normal file
70
lib/storage/favorites.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
'use client';
|
||||
|
||||
const FAVORITES_KEY = 'figlet-ui-favorites';
|
||||
const RECENT_FONTS_KEY = 'figlet-ui-recent-fonts';
|
||||
const MAX_RECENT = 10;
|
||||
|
||||
export function getFavorites(): string[] {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(FAVORITES_KEY);
|
||||
return stored ? JSON.parse(stored) : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function addFavorite(fontName: string): void {
|
||||
const favorites = getFavorites();
|
||||
if (!favorites.includes(fontName)) {
|
||||
favorites.push(fontName);
|
||||
localStorage.setItem(FAVORITES_KEY, JSON.stringify(favorites));
|
||||
}
|
||||
}
|
||||
|
||||
export function removeFavorite(fontName: string): void {
|
||||
const favorites = getFavorites();
|
||||
const filtered = favorites.filter(f => f !== fontName);
|
||||
localStorage.setItem(FAVORITES_KEY, JSON.stringify(filtered));
|
||||
}
|
||||
|
||||
export function isFavorite(fontName: string): boolean {
|
||||
return getFavorites().includes(fontName);
|
||||
}
|
||||
|
||||
export function toggleFavorite(fontName: string): boolean {
|
||||
const isCurrentlyFavorite = isFavorite(fontName);
|
||||
if (isCurrentlyFavorite) {
|
||||
removeFavorite(fontName);
|
||||
} else {
|
||||
addFavorite(fontName);
|
||||
}
|
||||
return !isCurrentlyFavorite;
|
||||
}
|
||||
|
||||
export function getRecentFonts(): string[] {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(RECENT_FONTS_KEY);
|
||||
return stored ? JSON.parse(stored) : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function addRecentFont(fontName: string): void {
|
||||
let recent = getRecentFonts();
|
||||
|
||||
// Remove if already exists
|
||||
recent = recent.filter(f => f !== fontName);
|
||||
|
||||
// Add to beginning
|
||||
recent.unshift(fontName);
|
||||
|
||||
// Keep only MAX_RECENT items
|
||||
recent = recent.slice(0, MAX_RECENT);
|
||||
|
||||
localStorage.setItem(RECENT_FONTS_KEY, JSON.stringify(recent));
|
||||
}
|
||||
53
lib/storage/history.ts
Normal file
53
lib/storage/history.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
'use client';
|
||||
|
||||
export interface HistoryItem {
|
||||
id: string;
|
||||
text: string;
|
||||
font: string;
|
||||
result: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
const HISTORY_KEY = 'figlet-ui-history';
|
||||
const MAX_HISTORY = 10;
|
||||
|
||||
export function getHistory(): HistoryItem[] {
|
||||
if (typeof window === 'undefined') return [];
|
||||
|
||||
try {
|
||||
const stored = localStorage.getItem(HISTORY_KEY);
|
||||
return stored ? JSON.parse(stored) : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
export function addToHistory(text: string, font: string, result: string): void {
|
||||
let history = getHistory();
|
||||
|
||||
const newItem: HistoryItem = {
|
||||
id: `${Date.now()}-${Math.random()}`,
|
||||
text,
|
||||
font,
|
||||
result,
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
// Add to beginning
|
||||
history.unshift(newItem);
|
||||
|
||||
// Keep only MAX_HISTORY items
|
||||
history = history.slice(0, MAX_HISTORY);
|
||||
|
||||
localStorage.setItem(HISTORY_KEY, JSON.stringify(history));
|
||||
}
|
||||
|
||||
export function clearHistory(): void {
|
||||
localStorage.removeItem(HISTORY_KEY);
|
||||
}
|
||||
|
||||
export function removeHistoryItem(id: string): void {
|
||||
const history = getHistory();
|
||||
const filtered = history.filter(item => item.id !== id);
|
||||
localStorage.setItem(HISTORY_KEY, JSON.stringify(filtered));
|
||||
}
|
||||
Reference in New Issue
Block a user