File size: 3,129 Bytes
07bbbbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * Ionic Theme Configuration
 * 
 * Provides comprehensive theme configuration for the application including light and dark modes.
 * Supports multiple predefined themes and system preference detection.
 * Follows Ionic best practices with CSS variables for consistent styling.
 */

/**
 * Theme preset names - Ionic platform modes
 */
export type ThemePreset = 'ios' | 'md' | 'auto';

/**
 * Theme mode options
 */
export type ThemeMode = 'light' | 'dark' | 'auto';

/**
 * Theme configuration interface
 */
export interface ThemeConfig {
  preset: ThemePreset;
  mode: 'light' | 'dark';
}

/**
 * Apply theme to document root
 * Simplified to just toggle dark mode and platform mode (iOS vs Material Design)
 */
export function applyIonicTheme(config: ThemeConfig): void {
  const root = document.documentElement;
  
  // Toggle dark mode class
  if (config.mode === 'dark') {
    root.classList.add('ion-palette-dark');
  } else {
    root.classList.remove('ion-palette-dark');
  }
  
  // Font family
  root.style.setProperty('--ion-font-family', [
    '-apple-system',
    'BlinkMacSystemFont',
    '"Segoe UI"',
    'Roboto',
    '"Helvetica Neue"',
    'Arial',
    'sans-serif',
    '"Apple Color Emoji"',
    '"Segoe UI Emoji"',
    '"Segoe UI Symbol"',
    '"Microsoft YaHei"',
    '"PingFang SC"',
    '"Hiragino Sans GB"',
    '"WenQuanYi Micro Hei"',
  ].join(','));
}

/**
 * Detect system platform preference
 */
export function getSystemPlatformPreference(): 'ios' | 'md' {
  if (typeof window !== 'undefined') {
    const platform = navigator.platform.toLowerCase();
    const userAgent = navigator.userAgent.toLowerCase();
    
    // Check if it's macOS or iOS
    if (platform.includes('mac') || 
        platform.includes('iphone') || 
        platform.includes('ipad') ||
        userAgent.includes('mac') ||
        userAgent.includes('iphone') ||
        userAgent.includes('ipad')) {
      return 'ios';
    }
  }
  return 'md';
}

/**
 * Detect system theme preference
 */
export function getSystemThemePreference(): 'light' | 'dark' {
  if (typeof window !== 'undefined' && window.matchMedia) {
    return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
  }
  return 'light';
}

/**
 * Get effective theme preset based on user preference and system
 */
export function getEffectiveThemePreset(themePreset: ThemePreset): 'ios' | 'md' {
  if (themePreset === 'auto') {
    return getSystemPlatformPreference();
  }
  return themePreset as 'ios' | 'md';
}

/**
 * Get effective theme mode based on user preference and system
 */
export function getEffectiveThemeMode(themeMode: ThemeMode): 'light' | 'dark' {
  if (themeMode === 'auto') {
    return getSystemThemePreference();
  }
  return themeMode as 'light' | 'dark';
}

/**
 * Theme preset labels for UI
 */
export const THEME_PRESET_LABELS: Record<ThemePreset, string> = {
  'ios': 'iOS',
  'md': 'Material Design',
  'auto': '自动识别',
};

/**
 * Theme mode labels for UI
 */
export const THEME_MODE_LABELS: Record<ThemeMode, string> = {
  'light': '浅色',
  'dark': '深色',
  'auto': '跟随系统',
};