@agions/taroviz 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +53 -41
  2. package/dist/cjs/index.js +1 -0
  3. package/dist/esm/index.js +9103 -0
  4. package/package.json +99 -10
  5. package/src/adapters/__tests__/index.test.ts +2 -2
  6. package/src/adapters/h5/index.ts +1 -1
  7. package/src/adapters/index.ts +99 -167
  8. package/src/charts/bar/index.tsx +2 -11
  9. package/src/charts/common/BaseChartWrapper.tsx +2 -2
  10. package/src/charts/funnel/index.tsx +2 -17
  11. package/src/charts/gauge/index.tsx +2 -17
  12. package/src/charts/heatmap/index.tsx +2 -17
  13. package/src/charts/index.ts +6 -1
  14. package/src/charts/line/index.tsx +2 -11
  15. package/src/charts/pie/index.tsx +3 -6
  16. package/src/charts/radar/index.tsx +2 -17
  17. package/src/charts/sankey/index.tsx +18 -0
  18. package/src/charts/scatter/index.tsx +2 -17
  19. package/src/charts/sunburst/index.tsx +18 -0
  20. package/src/charts/treemap/index.tsx +18 -0
  21. package/src/charts/types.ts +761 -30
  22. package/src/charts/utils.ts +1 -1
  23. package/src/core/__tests__/platform.test.ts +1 -1
  24. package/src/core/animation/AnimationManager.ts +2 -2
  25. package/src/core/components/Annotation.tsx +346 -0
  26. package/src/core/components/BaseChart.tsx +12 -18
  27. package/src/core/components/ErrorBoundary.tsx +153 -0
  28. package/src/core/components/LazyChart.tsx +200 -0
  29. package/src/core/echarts.ts +80 -0
  30. package/src/core/index.ts +4 -1
  31. package/src/core/themes/ThemeManager.ts +628 -0
  32. package/src/core/utils/__tests__/common.test.ts +1 -1
  33. package/src/core/utils/chartInstances.ts +2 -2
  34. package/src/core/utils/codeGenerator/CodeGenerator.ts +2 -2
  35. package/src/core/utils/codeGenerator/types.ts +0 -2
  36. package/src/core/utils/configGenerator/ConfigGenerator.ts +12 -12
  37. package/src/core/utils/debug/DebugPanel.tsx +1 -1
  38. package/src/core/utils/debug/debugger.ts +1 -1
  39. package/src/core/utils/export/ExportUtils.ts +385 -0
  40. package/src/core/utils/index.ts +1 -1
  41. package/src/core/utils/performance/PerformanceAnalyzer.ts +5 -5
  42. package/src/editor/ThemeEditor.tsx +9 -9
  43. package/src/hooks/index.ts +441 -61
  44. package/src/index.ts +72 -4
  45. package/src/main.tsx +1 -1
  46. package/src/themes/index.ts +651 -256
  47. package/dist/index.esm.js +0 -68685
@@ -1,8 +1,12 @@
1
1
  /**
2
- * TaroViz 主题系统
2
+ * TaroViz 主题系统 - 扩展版
3
3
  * 提供图表主题配置和自定义主题功能
4
4
  */
5
5
 
6
+ // ============================================================================
7
+ // 类型定义
8
+ // ============================================================================
9
+
6
10
  /**
7
11
  * 内置主题类型
8
12
  */
@@ -21,123 +25,217 @@ export type BuiltinTheme =
21
25
  | 'purple-passion'
22
26
  | 'blue-green'
23
27
  | 'golden'
24
- | 'forest';
28
+ | 'forest'
29
+ // 新增主题
30
+ | 'neon'
31
+ | 'glass'
32
+ | 'pastel'
33
+ | 'sunset'
34
+ | 'ocean'
35
+ | 'cyber'
36
+ | 'retro'
37
+ | 'elegant';
38
+
39
+ /**
40
+ * 主题模式
41
+ */
42
+ export type ThemeMode = 'light' | 'dark' | 'auto';
43
+
44
+ /**
45
+ * 主题渐变类型
46
+ */
47
+ export interface ThemeGradient {
48
+ /** 渐变起始色 */
49
+ start: string;
50
+ /** 渐变结束色 */
51
+ end: string;
52
+ /** 渐变角度 */
53
+ angle?: number;
54
+ }
55
+
56
+ /**
57
+ * 主题效果配置
58
+ */
59
+ export interface ThemeEffects {
60
+ /** 是否启用阴影 */
61
+ shadows?: boolean;
62
+ /** 阴影颜色 */
63
+ shadowColor?: string;
64
+ /** 是否启用渐变 */
65
+ gradients?: boolean;
66
+ /** 自定义渐变 */
67
+ customGradients?: ThemeGradient[];
68
+ /** 是否启用玻璃态 */
69
+ glassmorphism?: boolean;
70
+ /** 玻璃态模糊度 */
71
+ blur?: number;
72
+ /** 圆角风格 */
73
+ borderRadius?: 'none' | 'small' | 'medium' | 'large' | 'pill';
74
+ }
25
75
 
26
76
  /**
27
77
  * 主题配置选项
28
78
  */
29
79
  export interface ThemeOptions {
30
- /**
31
- * 主题类型
32
- */
33
- theme?: BuiltinTheme | Record<string, any>;
34
-
35
- /**
36
- * 是否启用深色模式
37
- */
80
+ /** 主题名称/键名 */
81
+ theme?: BuiltinTheme | Record<string, unknown>;
82
+
83
+ /** 是否启用深色模式 */
38
84
  darkMode?: boolean;
39
85
 
40
- /**
41
- * 颜色列表
42
- */
86
+ /** 主题模式 */
87
+ mode?: ThemeMode;
88
+
89
+ /** 颜色列表 */
43
90
  colors?: string[];
44
91
 
45
- /**
46
- * 背景色
47
- */
92
+ /** 背景色 */
48
93
  backgroundColor?: string;
49
94
 
50
- /**
51
- * 文本颜色
52
- */
95
+ /** 背景渐变 */
96
+ backgroundGradient?: ThemeGradient;
97
+
98
+ /** 文本颜色 */
53
99
  textColor?: string;
54
100
 
55
- /**
56
- * 字体
57
- */
101
+ /** 次要文本颜色 */
102
+ textColorSecondary?: string;
103
+
104
+ /** 边框颜色 */
105
+ borderColor?: string;
106
+
107
+ /** 分割线颜色 */
108
+ dividerColor?: string;
109
+
110
+ /** 字体 */
58
111
  fontFamily?: string;
59
112
 
60
- /**
61
- * 主题名称
62
- */
113
+ /** 标题字体 */
114
+ fontFamilyTitle?: string;
115
+
116
+ /** 正文字体 */
117
+ fontFamilyBody?: string;
118
+
119
+ /** 主题名称(显示用) */
63
120
  name?: string;
64
121
 
65
- /**
66
- * 主题描述
67
- */
122
+ /** 主题描述 */
68
123
  description?: string;
69
124
 
70
- /**
71
- * 主题作者
72
- */
125
+ /** 主题作者 */
73
126
  author?: string;
74
127
 
75
- /**
76
- * 主题版本
77
- */
128
+ /** 主题版本 */
78
129
  version?: string;
79
130
 
80
- /**
81
- * 主题类型
82
- */
83
- type?: 'light' | 'dark' | 'auto';
84
-
85
- /**
86
- * 图表特定配置
87
- */
88
- chart?: {
89
- /**
90
- * 图例配置
91
- */
92
- legend?: {
93
- textColor?: string;
94
- backgroundColor?: string;
95
- borderColor?: string;
96
- };
97
-
98
- /**
99
- * 坐标轴配置
100
- */
101
- axis?: {
102
- textColor?: string;
103
- lineColor?: string;
104
- tickColor?: string;
105
- splitLineColor?: string;
106
- };
107
-
108
- /**
109
- * 提示框配置
110
- */
111
- tooltip?: {
112
- textColor?: string;
113
- backgroundColor?: string;
114
- borderColor?: string;
115
- };
116
-
117
- /**
118
- * 标题配置
119
- */
120
- title?: {
121
- textColor?: string;
122
- subTextColor?: string;
123
- };
124
- };
131
+ /** 主题类型 */
132
+ type?: ThemeMode;
133
+
134
+ /** 主题标签 */
135
+ tags?: string[];
136
+
137
+ /** 效果配置 */
138
+ effects?: ThemeEffects;
139
+
140
+ /** 图表特定配置 */
141
+ chart?: ChartThemeConfig;
125
142
  }
126
143
 
127
144
  /**
128
- * 主题注册表
145
+ * 图表主题配置
129
146
  */
147
+ export interface ChartThemeConfig {
148
+ /** 图例配置 */
149
+ legend?: LegendThemeConfig;
150
+ /** 坐标轴配置 */
151
+ axis?: AxisThemeConfig;
152
+ /** 提示框配置 */
153
+ tooltip?: TooltipThemeConfig;
154
+ /** 标题配置 */
155
+ title?: TitleThemeConfig;
156
+ /** 网格配置 */
157
+ grid?: GridThemeConfig;
158
+ /** 数据区域缩放配置 */
159
+ dataZoom?: DataZoomThemeConfig;
160
+ /** 时间线配置 */
161
+ timeline?: TimelineThemeConfig;
162
+ }
163
+
164
+ /** 图例主题配置 */
165
+ export interface LegendThemeConfig {
166
+ textColor?: string;
167
+ backgroundColor?: string;
168
+ borderColor?: string;
169
+ borderRadius?: number | number[];
170
+ padding?: number | number[];
171
+ }
172
+
173
+ /** 坐标轴主题配置 */
174
+ export interface AxisThemeConfig {
175
+ textColor?: string;
176
+ lineColor?: string;
177
+ tickColor?: string;
178
+ splitLineColor?: string;
179
+ splitAreaColor?: string;
180
+ }
181
+
182
+ /** 提示框主题配置 */
183
+ export interface TooltipThemeConfig {
184
+ textColor?: string;
185
+ backgroundColor?: string;
186
+ borderColor?: string;
187
+ borderRadius?: number;
188
+ shadowColor?: string;
189
+ }
190
+
191
+ /** 标题主题配置 */
192
+ export interface TitleThemeConfig {
193
+ textColor?: string;
194
+ subTextColor?: string;
195
+ }
196
+
197
+ /** 网格主题配置 */
198
+ export interface GridThemeConfig {
199
+ backgroundColor?: string;
200
+ borderColor?: string;
201
+ }
202
+
203
+ /** 数据区域缩放主题配置 */
204
+ export interface DataZoomThemeConfig {
205
+ backgroundColor?: string;
206
+ fillerColor?: string;
207
+ borderColor?: string;
208
+ textColor?: string;
209
+ }
210
+
211
+ /** 时间线主题配置 */
212
+ export interface TimelineThemeConfig {
213
+ backgroundColor?: string;
214
+ borderColor?: string;
215
+ textColor?: string;
216
+ lineColor?: string;
217
+ controlColor?: string;
218
+ }
219
+
220
+ // ============================================================================
221
+ // 主题注册表
222
+ // ============================================================================
223
+
130
224
  const themeRegistry = new Map<string, ThemeOptions>();
131
225
 
132
- /**
133
- * 默认主题配置
134
- */
226
+ // ============================================================================
227
+ // 内置主题定义
228
+ // ============================================================================
229
+
230
+ /** 默认主题 */
135
231
  export const defaultTheme: ThemeOptions = {
136
232
  theme: 'default',
137
- name: 'default',
138
- description: '默认主题',
233
+ name: 'Default',
234
+ description: '简洁现代的默认主题',
139
235
  type: 'light',
236
+ mode: 'light',
140
237
  darkMode: false,
238
+ tags: ['modern', 'clean', 'default'],
141
239
  colors: [
142
240
  '#5470c6',
143
241
  '#91cc75',
@@ -149,21 +247,46 @@ export const defaultTheme: ThemeOptions = {
149
247
  '#9a60b4',
150
248
  '#ea7ccc',
151
249
  ],
152
- backgroundColor: 'transparent',
153
- textColor: '#333',
154
- fontFamily:
155
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
250
+ backgroundColor: '#ffffff',
251
+ textColor: '#333333',
252
+ textColorSecondary: '#666666',
253
+ borderColor: '#e8e8e8',
254
+ dividerColor: '#f0f0f0',
255
+ fontFamily: 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
256
+ chart: {
257
+ legend: {
258
+ textColor: '#333333',
259
+ backgroundColor: 'transparent',
260
+ borderColor: '#e8e8e8',
261
+ },
262
+ axis: {
263
+ textColor: '#666666',
264
+ lineColor: '#e8e8e8',
265
+ tickColor: '#e8e8e8',
266
+ splitLineColor: '#f0f0f0',
267
+ },
268
+ tooltip: {
269
+ textColor: '#333333',
270
+ backgroundColor: 'rgba(255, 255, 255, 0.95)',
271
+ borderColor: '#e8e8e8',
272
+ borderRadius: 4,
273
+ },
274
+ title: {
275
+ textColor: '#333333',
276
+ subTextColor: '#666666',
277
+ },
278
+ },
156
279
  };
157
280
 
158
- /**
159
- * 深色主题配置
160
- */
281
+ /** 深色主题 */
161
282
  export const darkTheme: ThemeOptions = {
162
283
  theme: 'dark',
163
- name: 'dark',
164
- description: '深色主题',
284
+ name: 'Dark',
285
+ description: '优雅的深色主题,适合夜间使用',
165
286
  type: 'dark',
287
+ mode: 'dark',
166
288
  darkMode: true,
289
+ tags: ['dark', 'night', 'modern'],
167
290
  colors: [
168
291
  '#4992ff',
169
292
  '#7cffb2',
@@ -175,156 +298,352 @@ export const darkTheme: ThemeOptions = {
175
298
  '#8d48e3',
176
299
  '#dd79ff',
177
300
  ],
178
- backgroundColor: '#0f1117',
179
- textColor: '#e1e1e1',
180
- fontFamily:
181
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
301
+ backgroundColor: '#1a1a2e',
302
+ textColor: '#e8e8e8',
303
+ textColorSecondary: '#a0a0a0',
304
+ borderColor: '#2d2d44',
305
+ dividerColor: '#252538',
306
+ fontFamily: 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
307
+ chart: {
308
+ legend: {
309
+ textColor: '#e8e8e8',
310
+ backgroundColor: 'transparent',
311
+ borderColor: '#2d2d44',
312
+ },
313
+ axis: {
314
+ textColor: '#a0a0a0',
315
+ lineColor: '#2d2d44',
316
+ tickColor: '#2d2d44',
317
+ splitLineColor: '#252538',
318
+ },
319
+ tooltip: {
320
+ textColor: '#e8e8e8',
321
+ backgroundColor: 'rgba(26, 26, 46, 0.95)',
322
+ borderColor: '#2d2d44',
323
+ borderRadius: 4,
324
+ },
325
+ title: {
326
+ textColor: '#e8e8e8',
327
+ subTextColor: '#a0a0a0',
328
+ },
329
+ },
182
330
  };
183
331
 
184
- /**
185
- * Walden 主题配置
186
- */
187
- export const waldenTheme: ThemeOptions = {
188
- theme: 'walden',
332
+ /** Neon 霓虹主题 */
333
+ export const neonTheme: ThemeOptions = {
334
+ theme: 'neon',
335
+ name: 'Neon',
336
+ description: '赛博朋克霓虹风格,炫酷吸睛',
337
+ type: 'dark',
338
+ mode: 'dark',
339
+ darkMode: true,
340
+ tags: ['neon', 'cyberpunk', 'colorful', 'dark'],
341
+ colors: [
342
+ '#00fff5',
343
+ '#ff00ff',
344
+ '#ffff00',
345
+ '#00ff00',
346
+ '#ff6b6b',
347
+ '#4ecdc4',
348
+ '#ffe66d',
349
+ '#95e1d3',
350
+ '#f38181',
351
+ ],
352
+ backgroundColor: '#0d0d1a',
353
+ textColor: '#ffffff',
354
+ textColorSecondary: '#b0b0b0',
355
+ borderColor: '#1a1a2e',
356
+ dividerColor: '#1a1a2e',
357
+ fontFamily: '"JetBrains Mono", "Fira Code", monospace',
358
+ effects: {
359
+ shadows: true,
360
+ shadowColor: 'rgba(0, 255, 245, 0.3)',
361
+ gradients: true,
362
+ },
363
+ chart: {
364
+ tooltip: {
365
+ textColor: '#ffffff',
366
+ backgroundColor: 'rgba(13, 13, 26, 0.95)',
367
+ borderColor: '#00fff5',
368
+ borderRadius: 4,
369
+ shadowColor: 'rgba(0, 255, 245, 0.3)',
370
+ },
371
+ },
372
+ };
373
+
374
+ /** Glass 玻璃态主题 */
375
+ export const glassTheme: ThemeOptions = {
376
+ theme: 'glass',
377
+ name: 'Glass',
378
+ description: '现代玻璃态设计,半透明质感',
379
+ type: 'light',
380
+ mode: 'light',
189
381
  darkMode: false,
382
+ tags: ['glass', 'modern', 'minimal', 'light'],
190
383
  colors: [
191
- '#0a437a',
192
- '#3a84c4',
193
- '#22a783',
194
- '#48b591',
195
- '#7fcdbb',
196
- '#c9e4ca',
197
- '#eef7d5',
198
- '#fdf0d5',
199
- '#fbb573',
200
- '#f89540',
384
+ '#667eea',
385
+ '#764ba2',
386
+ '#f093fb',
387
+ '#f5576c',
388
+ '#4facfe',
389
+ '#00f2fe',
390
+ '#43e97b',
391
+ '#38f9d7',
392
+ '#fa709a',
201
393
  ],
202
- backgroundColor: '#f0f8f5',
203
- textColor: '#2c5042',
204
- fontFamily:
205
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
394
+ backgroundColor: 'rgba(255, 255, 255, 0.8)',
395
+ backgroundGradient: {
396
+ start: '#f5f7fa',
397
+ end: '#c3cfe2',
398
+ angle: 135,
399
+ },
400
+ textColor: '#2d3748',
401
+ textColorSecondary: '#718096',
402
+ borderColor: 'rgba(255, 255, 255, 0.5)',
403
+ dividerColor: 'rgba(255, 255, 255, 0.3)',
404
+ fontFamily: 'Inter, -apple-system, BlinkMacSystemFont, sans-serif',
405
+ effects: {
406
+ glassmorphism: true,
407
+ blur: 10,
408
+ shadows: true,
409
+ shadowColor: 'rgba(0, 0, 0, 0.1)',
410
+ borderRadius: 'large',
411
+ },
412
+ chart: {
413
+ tooltip: {
414
+ textColor: '#2d3748',
415
+ backgroundColor: 'rgba(255, 255, 255, 0.9)',
416
+ borderColor: 'rgba(255, 255, 255, 0.5)',
417
+ borderRadius: 12,
418
+ },
419
+ },
206
420
  };
207
421
 
208
- /**
209
- * Chalk 主题配置
210
- */
211
- export const chalkTheme: ThemeOptions = {
212
- theme: 'chalk',
422
+ /** Pastel 粉彩主题 */
423
+ export const pastelTheme: ThemeOptions = {
424
+ theme: 'pastel',
425
+ name: 'Pastel',
426
+ description: '柔和粉彩配色,温馨舒适',
427
+ type: 'light',
428
+ mode: 'light',
213
429
  darkMode: false,
430
+ tags: ['pastel', 'soft', 'gentle', 'light'],
214
431
  colors: [
215
- '#2e8de5',
216
- '#f0805a',
217
- '#5ab1ef',
218
- '#91d5ff',
219
- '#faad14',
220
- '#fadb14',
221
- '#52c41a',
222
- '#13c2c2',
223
- '#722ed1',
224
- '#eb2f96',
432
+ '#ffb3ba',
433
+ '#ffdfba',
434
+ '#ffffba',
435
+ '#baffc9',
436
+ '#bae1ff',
437
+ '#f0b3ff',
438
+ '#b3fff0',
439
+ '#ffb3d9',
440
+ '#d9ffb3',
225
441
  ],
226
- backgroundColor: '#ffffff',
227
- textColor: '#000000',
228
- fontFamily:
229
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
442
+ backgroundColor: '#fff9f5',
443
+ textColor: '#5d5d5d',
444
+ textColorSecondary: '#8a8a8a',
445
+ borderColor: '#f0e6e0',
446
+ dividerColor: '#f5f0eb',
447
+ fontFamily: 'Nunito, -apple-system, BlinkMacSystemFont, sans-serif',
448
+ chart: {
449
+ tooltip: {
450
+ textColor: '#5d5d5d',
451
+ backgroundColor: 'rgba(255, 255, 255, 0.95)',
452
+ borderColor: '#f0e6e0',
453
+ borderRadius: 8,
454
+ },
455
+ },
230
456
  };
231
457
 
232
- /**
233
- * Purple Passion 主题配置
234
- */
235
- export const purplePassionTheme: ThemeOptions = {
236
- theme: 'purple-passion',
458
+ /** Sunset 日落主题 */
459
+ export const sunsetTheme: ThemeOptions = {
460
+ theme: 'sunset',
461
+ name: 'Sunset',
462
+ description: '温暖日落渐变,夕阳余晖',
463
+ type: 'light',
464
+ mode: 'light',
237
465
  darkMode: false,
466
+ tags: ['sunset', 'warm', 'gradient', 'light'],
238
467
  colors: [
239
- '#9c27b0',
240
- '#e91e63',
241
- '#ff5722',
242
- '#ff9800',
243
- '#ffc107',
244
- '#8bc34a',
245
- '#4caf50',
246
- '#009688',
247
- '#00bcd4',
248
- '#2196f3',
468
+ '#ff6b6b',
469
+ '#feca57',
470
+ '#ff9ff3',
471
+ '#54a0ff',
472
+ '#5f27cd',
473
+ '#ff9f43',
474
+ '#ee5a24',
475
+ '#009432',
476
+ '#f368e0',
249
477
  ],
250
- backgroundColor: '#f5f5f5',
251
- textColor: '#333333',
252
- fontFamily:
253
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
478
+ backgroundColor: '#fff5f0',
479
+ backgroundGradient: {
480
+ start: '#ffecd2',
481
+ end: '#fcb69f',
482
+ angle: 135,
483
+ },
484
+ textColor: '#4a4a4a',
485
+ textColorSecondary: '#7a7a7a',
486
+ borderColor: '#ffd5c8',
487
+ dividerColor: '#ffebe6',
488
+ fontFamily: 'Quicksand, -apple-system, BlinkMacSystemFont, sans-serif',
489
+ effects: {
490
+ gradients: true,
491
+ shadows: true,
492
+ shadowColor: 'rgba(255, 107, 107, 0.2)',
493
+ borderRadius: 'medium',
494
+ },
254
495
  };
255
496
 
256
- /**
257
- * Blue Green 主题配置
258
- */
259
- export const blueGreenTheme: ThemeOptions = {
260
- theme: 'blue-green',
497
+ /** Ocean 海洋主题 */
498
+ export const oceanTheme: ThemeOptions = {
499
+ theme: 'ocean',
500
+ name: 'Ocean',
501
+ description: '深邃海洋蓝,宁静清新',
502
+ type: 'light',
503
+ mode: 'light',
261
504
  darkMode: false,
505
+ tags: ['ocean', 'blue', 'calm', 'light'],
262
506
  colors: [
263
- '#00838f',
264
- '#00acc1',
265
- '#03a9f4',
266
- '#29b6f6',
267
- '#4fc3f7',
268
- '#81d4fa',
269
- '#b3e5fc',
270
- '#e1f5fe',
271
- '#80deea',
272
- '#4dd0e1',
507
+ '#0077b6',
508
+ '#00b4d8',
509
+ '#90e0ef',
510
+ '#caf0f8',
511
+ '#03045e',
512
+ '#023e8a',
513
+ '#0096c7',
514
+ '#48cae4',
515
+ '#ade8f4',
273
516
  ],
274
- backgroundColor: '#e0f7fa',
275
- textColor: '#006064',
276
- fontFamily:
277
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
517
+ backgroundColor: '#f0f8ff',
518
+ backgroundGradient: {
519
+ start: '#e0f2fe',
520
+ end: '#bae6fd',
521
+ angle: 180,
522
+ },
523
+ textColor: '#1e3a5f',
524
+ textColorSecondary: '#4a6fa5',
525
+ borderColor: '#cce7f5',
526
+ dividerColor: '#e1f0f9',
527
+ fontFamily: 'Nunito, -apple-system, BlinkMacSystemFont, sans-serif',
528
+ effects: {
529
+ gradients: true,
530
+ shadows: true,
531
+ shadowColor: 'rgba(0, 119, 182, 0.15)',
532
+ },
278
533
  };
279
534
 
280
- /**
281
- * Golden 主题配置
282
- */
283
- export const goldenTheme: ThemeOptions = {
284
- theme: 'golden',
535
+ /** Cyber 赛博主题 */
536
+ export const cyberTheme: ThemeOptions = {
537
+ theme: 'cyber',
538
+ name: 'Cyber',
539
+ description: '未来科技感,赛博朋克',
540
+ type: 'dark',
541
+ mode: 'dark',
542
+ darkMode: true,
543
+ tags: ['cyber', 'tech', 'futuristic', 'dark'],
544
+ colors: [
545
+ '#00f5ff',
546
+ '#ff00ff',
547
+ '#00ff00',
548
+ '#ffff00',
549
+ '#ff0080',
550
+ '#8000ff',
551
+ '#00ff80',
552
+ '#ff8000',
553
+ '#0080ff',
554
+ ],
555
+ backgroundColor: '#0a0a12',
556
+ textColor: '#e0e0e0',
557
+ textColorSecondary: '#808090',
558
+ borderColor: '#1a1a2e',
559
+ dividerColor: '#12121e',
560
+ fontFamily: '"Orbitron", "Rajdhani", "JetBrains Mono", monospace',
561
+ effects: {
562
+ shadows: true,
563
+ shadowColor: 'rgba(0, 245, 255, 0.4)',
564
+ gradients: true,
565
+ borderRadius: 'none',
566
+ },
567
+ chart: {
568
+ tooltip: {
569
+ textColor: '#ffffff',
570
+ backgroundColor: 'rgba(10, 10, 18, 0.95)',
571
+ borderColor: '#00f5ff',
572
+ borderRadius: 0,
573
+ shadowColor: 'rgba(0, 245, 255, 0.4)',
574
+ },
575
+ },
576
+ };
577
+
578
+ /** Retro 复古主题 */
579
+ export const retroTheme: ThemeOptions = {
580
+ theme: 'retro',
581
+ name: 'Retro',
582
+ description: '怀旧复古风格,温馨怀旧',
583
+ type: 'light',
584
+ mode: 'light',
285
585
  darkMode: false,
586
+ tags: ['retro', 'vintage', 'nostalgic', 'light'],
286
587
  colors: [
287
- '#ffd700',
288
- '#ffed4e',
289
- '#f9a825',
290
- '#ffc107',
291
- '#ffb300',
292
- '#ffa000',
293
- '#ff8f00',
294
- '#ff6f00',
295
- '#ff5722',
296
- '#e64a19',
588
+ '#d63031',
589
+ '#e17055',
590
+ '#fdcb6e',
591
+ '#00b894',
592
+ '#0984e3',
593
+ '#6c5ce7',
594
+ '#e84393',
595
+ '#00cec9',
596
+ '#fab1a0',
297
597
  ],
298
- backgroundColor: '#fff8e1',
299
- textColor: '#ff6f00',
300
- fontFamily:
301
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
598
+ backgroundColor: '#fdf6e3',
599
+ textColor: '#5c4b37',
600
+ textColorSecondary: '#8b7355',
601
+ borderColor: '#e8dcc8',
602
+ dividerColor: '#f0e8d8',
603
+ fontFamily: '"Courier Prime", "Courier New", monospace',
604
+ effects: {
605
+ shadows: false,
606
+ borderRadius: 'small',
607
+ },
302
608
  };
303
609
 
304
- /**
305
- * Forest 主题配置
306
- */
307
- export const forestTheme: ThemeOptions = {
308
- theme: 'forest',
610
+ /** Elegant 雅致主题 */
611
+ export const elegantTheme: ThemeOptions = {
612
+ theme: 'elegant',
613
+ name: 'Elegant',
614
+ description: '低调雅致风格,精致品味',
615
+ type: 'light',
616
+ mode: 'light',
309
617
  darkMode: false,
618
+ tags: ['elegant', 'minimal', 'sophisticated', 'light'],
310
619
  colors: [
311
- '#2e7d32',
312
- '#388e3c',
313
- '#43a047',
314
- '#4caf50',
315
- '#66bb6a',
316
- '#81c784',
317
- '#a5d6a7',
318
- '#c8e6c9',
319
- '#e8f5e8',
320
- '#f1f8e9',
620
+ '#2c3e50',
621
+ '#34495e',
622
+ '#7f8c8d',
623
+ '#95a5a6',
624
+ '#bdc3c7',
625
+ '#ecf0f1',
626
+ '#1abc9c',
627
+ '#16a085',
628
+ '#3498db',
321
629
  ],
322
- backgroundColor: '#f1f8e9',
323
- textColor: '#1b5e20',
324
- fontFamily:
325
- '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
630
+ backgroundColor: '#fafafa',
631
+ textColor: '#2c3e50',
632
+ textColorSecondary: '#7f8c8d',
633
+ borderColor: '#e8e8e8',
634
+ dividerColor: '#f0f0f0',
635
+ fontFamily: '"Playfair Display", Georgia, serif',
636
+ effects: {
637
+ shadows: true,
638
+ shadowColor: 'rgba(0, 0, 0, 0.08)',
639
+ borderRadius: 'medium',
640
+ },
326
641
  };
327
642
 
643
+ // ============================================================================
644
+ // 主题管理函数
645
+ // ============================================================================
646
+
328
647
  /**
329
648
  * 获取主题配置
330
649
  * @param options 自定义选项
@@ -335,18 +654,15 @@ export function getTheme(options?: Partial<ThemeOptions>): ThemeOptions {
335
654
  return defaultTheme;
336
655
  }
337
656
 
338
- // 如果提供了主题名称,尝试从注册表中获取
339
657
  let baseTheme: ThemeOptions;
340
658
  if (options.theme && typeof options.theme === 'string') {
341
659
  const registeredTheme = themeRegistry.get(options.theme);
342
660
  if (registeredTheme) {
343
661
  baseTheme = registeredTheme;
344
662
  } else {
345
- // 如果主题不存在,使用默认主题
346
663
  baseTheme = options.darkMode ? darkTheme : defaultTheme;
347
664
  }
348
665
  } else {
349
- // 如果没有提供主题名称,使用默认主题或深色主题
350
666
  baseTheme = options.darkMode ? darkTheme : defaultTheme;
351
667
  }
352
668
 
@@ -359,12 +675,7 @@ export function getTheme(options?: Partial<ThemeOptions>): ThemeOptions {
359
675
  * @param theme 主题配置
360
676
  */
361
677
  export function registerTheme(name: string, theme: ThemeOptions): void {
362
- // 注册主题到主题注册表
363
- themeRegistry.set(name, {
364
- ...theme,
365
- name,
366
- });
367
- console.log(`Registering theme: ${name}`);
678
+ themeRegistry.set(name, { ...theme, name });
368
679
  }
369
680
 
370
681
  /**
@@ -390,76 +701,160 @@ export function getThemeByName(name: string): ThemeOptions | undefined {
390
701
  */
391
702
  export function unregisterTheme(name: string): void {
392
703
  themeRegistry.delete(name);
393
- console.log(`Theme unregistered: ${name}`);
394
704
  }
395
705
 
396
706
  /**
397
707
  * 动态切换主题
398
708
  * @param theme 主题名称或主题配置
399
709
  * @param callback 切换完成后的回调函数
710
+ * @returns 主题配置
400
711
  */
401
712
  export function switchTheme(theme: string | ThemeOptions, callback?: () => void): ThemeOptions {
402
713
  let themeConfig: ThemeOptions;
403
714
 
404
715
  if (typeof theme === 'string') {
405
- // 如果是主题名称,从注册表中获取
406
716
  const registeredTheme = themeRegistry.get(theme);
407
- if (registeredTheme) {
408
- themeConfig = registeredTheme;
409
- } else {
410
- // 如果主题不存在,使用默认主题
411
- themeConfig = defaultTheme;
412
- }
717
+ themeConfig = registeredTheme || defaultTheme;
413
718
  } else {
414
- // 如果是主题配置,直接使用
415
719
  themeConfig = theme;
416
- // 如果主题配置包含名称,注册到注册表
417
720
  if (theme.name) {
418
721
  registerTheme(theme.name, theme);
419
722
  }
420
723
  }
421
724
 
422
725
  // 触发主题切换事件
423
- const event = new CustomEvent('themeChange', {
424
- detail: themeConfig,
425
- });
426
-
427
- // 检查是否在浏览器环境中
428
726
  if (typeof window !== 'undefined') {
429
- window.dispatchEvent(event);
727
+ window.dispatchEvent(new CustomEvent('themeChange', { detail: themeConfig }));
430
728
  }
431
729
 
432
- // 调用回调函数
433
- if (callback) {
434
- callback();
435
- }
730
+ callback?.();
436
731
 
437
732
  return themeConfig;
438
733
  }
439
734
 
440
- // 注册内置主题
441
- themeRegistry.set('default', defaultTheme);
442
- themeRegistry.set('dark', darkTheme);
443
- themeRegistry.set('walden', waldenTheme);
444
- themeRegistry.set('chalk', chalkTheme);
445
- themeRegistry.set('purple-passion', purplePassionTheme);
446
- themeRegistry.set('blue-green', blueGreenTheme);
447
- themeRegistry.set('golden', goldenTheme);
448
- themeRegistry.set('forest', forestTheme);
735
+ /**
736
+ * 根据标签获取主题
737
+ * @param tag 标签
738
+ * @returns 主题列表
739
+ */
740
+ export function getThemesByTag(tag: string): ThemeOptions[] {
741
+ return getRegisteredThemes().filter((t) => t.tags?.includes(tag));
742
+ }
743
+
744
+ /**
745
+ * 获取浅色主题
746
+ * @returns 浅色主题列表
747
+ */
748
+ export function getLightThemes(): ThemeOptions[] {
749
+ return getRegisteredThemes().filter((t) => !t.darkMode);
750
+ }
751
+
752
+ /**
753
+ * 获取深色主题
754
+ * @returns 深色主题列表
755
+ */
756
+ export function getDarkThemes(): ThemeOptions[] {
757
+ return getRegisteredThemes().filter((t) => t.darkMode);
758
+ }
759
+
760
+ // ============================================================================
761
+ // 注册所有内置主题
762
+ // ============================================================================
763
+
764
+ const builtinThemes = {
765
+ default: defaultTheme,
766
+ dark: darkTheme,
767
+ walden: {
768
+ ...defaultTheme,
769
+ theme: 'walden',
770
+ name: 'Walden',
771
+ description: '清新自然风格',
772
+ colors: ['#0a437a', '#3a84c4', '#22a783', '#48b591', '#7fcdbb', '#c9e4ca'],
773
+ backgroundColor: '#f0f8f5',
774
+ textColor: '#2c5042',
775
+ },
776
+ chalk: {
777
+ ...defaultTheme,
778
+ theme: 'chalk',
779
+ name: 'Chalk',
780
+ description: '粉笔风格',
781
+ colors: ['#2e8de5', '#f0805a', '#5ab1ef', '#91d5ff', '#faad14'],
782
+ backgroundColor: '#ffffff',
783
+ textColor: '#000000',
784
+ },
785
+ 'purple-passion': {
786
+ ...defaultTheme,
787
+ theme: 'purple-passion',
788
+ name: 'Purple Passion',
789
+ description: '紫色浪漫',
790
+ colors: ['#9c27b0', '#e91e63', '#ff5722', '#ff9800', '#ffc107'],
791
+ backgroundColor: '#f5f5f5',
792
+ textColor: '#333333',
793
+ },
794
+ 'blue-green': {
795
+ ...defaultTheme,
796
+ theme: 'blue-green',
797
+ name: 'Blue Green',
798
+ description: '蓝绿清新',
799
+ colors: ['#00838f', '#00acc1', '#03a9f4', '#29b6f6', '#4fc3f7'],
800
+ backgroundColor: '#e0f7fa',
801
+ textColor: '#006064',
802
+ },
803
+ golden: {
804
+ ...defaultTheme,
805
+ theme: 'golden',
806
+ name: 'Golden',
807
+ description: '金色奢华',
808
+ colors: ['#ffd700', '#ffed4e', '#f9a825', '#ffc107', '#ffb300'],
809
+ backgroundColor: '#fff8e1',
810
+ textColor: '#ff6f00',
811
+ },
812
+ forest: {
813
+ ...defaultTheme,
814
+ theme: 'forest',
815
+ name: 'Forest',
816
+ description: '森林绿色',
817
+ colors: ['#2e7d32', '#388e3c', '#43a047', '#4caf50', '#66bb6a'],
818
+ backgroundColor: '#f1f8e9',
819
+ textColor: '#1b5e20',
820
+ },
821
+ neon: neonTheme,
822
+ glass: glassTheme,
823
+ pastel: pastelTheme,
824
+ sunset: sunsetTheme,
825
+ ocean: oceanTheme,
826
+ cyber: cyberTheme,
827
+ retro: retroTheme,
828
+ elegant: elegantTheme,
829
+ };
830
+
831
+ // 注册所有内置主题
832
+ Object.entries(builtinThemes).forEach(([name, theme]) => {
833
+ themeRegistry.set(name, theme as ThemeOptions);
834
+ });
835
+
836
+ // ============================================================================
837
+ // 导出
838
+ // ============================================================================
449
839
 
450
840
  export default {
451
841
  defaultTheme,
452
842
  darkTheme,
453
- waldenTheme,
454
- chalkTheme,
455
- purplePassionTheme,
456
- blueGreenTheme,
457
- goldenTheme,
458
- forestTheme,
843
+ neonTheme,
844
+ glassTheme,
845
+ pastelTheme,
846
+ sunsetTheme,
847
+ oceanTheme,
848
+ cyberTheme,
849
+ retroTheme,
850
+ elegantTheme,
459
851
  getTheme,
460
852
  registerTheme,
461
853
  getRegisteredThemes,
462
854
  getThemeByName,
463
855
  unregisterTheme,
464
856
  switchTheme,
857
+ getThemesByTag,
858
+ getLightThemes,
859
+ getDarkThemes,
465
860
  };