@agions/taroviz 1.1.1 → 1.2.1

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 (81) hide show
  1. package/README.md +324 -53
  2. package/dist/cjs/index.js +1 -0
  3. package/dist/esm/index.js +82979 -0
  4. package/package.json +160 -30
  5. package/src/__tests__/integration.test.tsx +168 -0
  6. package/src/adapters/__tests__/index.test.ts +91 -0
  7. package/src/adapters/h5/__tests__/index.test.ts +156 -0
  8. package/src/adapters/h5/index.ts +301 -0
  9. package/src/adapters/harmony/index.ts +274 -0
  10. package/src/adapters/index.ts +166 -0
  11. package/src/adapters/swan/index.ts +274 -0
  12. package/src/adapters/tt/index.ts +274 -0
  13. package/src/adapters/types.ts +162 -0
  14. package/src/adapters/weapp/index.ts +237 -0
  15. package/src/charts/bar/__tests__/index.test.tsx +113 -0
  16. package/src/charts/bar/index.tsx +18 -0
  17. package/src/charts/common/BaseChartWrapper.tsx +136 -0
  18. package/src/charts/funnel/index.tsx +18 -0
  19. package/src/charts/gauge/index.tsx +18 -0
  20. package/src/charts/heatmap/index.tsx +18 -0
  21. package/src/charts/index.ts +21 -0
  22. package/src/charts/line/__tests__/index.test.tsx +107 -0
  23. package/src/charts/line/index.tsx +18 -0
  24. package/src/charts/pie/__tests__/index.test.tsx +112 -0
  25. package/src/charts/pie/index.tsx +19 -0
  26. package/src/charts/radar/index.tsx +18 -0
  27. package/src/charts/scatter/index.tsx +18 -0
  28. package/src/charts/types.ts +619 -0
  29. package/src/charts/utils.ts +56 -0
  30. package/src/core/__tests__/platform.test.ts +48 -0
  31. package/src/core/animation/AnimationManager.ts +391 -0
  32. package/src/core/animation/index.ts +20 -0
  33. package/src/core/animation/types.ts +248 -0
  34. package/src/core/components/BaseChart.tsx +1313 -0
  35. package/src/core/components/ErrorBoundary.tsx +458 -0
  36. package/src/core/echarts.ts +58 -0
  37. package/src/core/index.ts +22 -0
  38. package/src/core/types/chart.ts +66 -0
  39. package/src/core/types/common.ts +224 -0
  40. package/src/core/types/index.ts +281 -0
  41. package/src/core/types/platform.ts +325 -0
  42. package/src/core/utils/__tests__/common.test.ts +52 -0
  43. package/src/core/utils/__tests__/environment.test.ts +94 -0
  44. package/src/core/utils/__tests__/i18n.test.ts +247 -0
  45. package/src/core/utils/__tests__/index.test.ts +219 -0
  46. package/src/core/utils/__tests__/uuid.test.ts +78 -0
  47. package/src/core/utils/chartInstances.ts +69 -0
  48. package/src/core/utils/codeGenerator/CodeGenerator.ts +655 -0
  49. package/src/core/utils/codeGenerator/index.ts +13 -0
  50. package/src/core/utils/codeGenerator/types.ts +198 -0
  51. package/src/core/utils/common.ts +58 -0
  52. package/src/core/utils/configGenerator/ConfigGenerator.ts +583 -0
  53. package/src/core/utils/configGenerator/index.ts +13 -0
  54. package/src/core/utils/configGenerator/types.ts +445 -0
  55. package/src/core/utils/debug/DebugPanel.tsx +637 -0
  56. package/src/core/utils/debug/debugger.ts +322 -0
  57. package/src/core/utils/debug/index.ts +21 -0
  58. package/src/core/utils/debug/types.ts +142 -0
  59. package/src/core/utils/i18n.ts +452 -0
  60. package/src/core/utils/index.ts +162 -0
  61. package/src/core/utils/performance/PerformanceAnalyzer.ts +586 -0
  62. package/src/core/utils/performance/index.ts +13 -0
  63. package/src/core/utils/performance/types.ts +180 -0
  64. package/src/core/utils/uuid.ts +30 -0
  65. package/src/editor/ThemeEditor.tsx +449 -0
  66. package/src/editor/index.ts +10 -0
  67. package/src/hooks/__tests__/index.test.tsx +333 -0
  68. package/src/hooks/index.ts +594 -0
  69. package/src/index.ts +75 -0
  70. package/src/main.tsx +247 -0
  71. package/src/react-dom.d.ts +7 -0
  72. package/src/themes/__tests__/index.test.ts +91 -0
  73. package/src/themes/index.ts +860 -0
  74. package/dist/389.index.esm.js +0 -1
  75. package/dist/389.index.js +0 -1
  76. package/dist/633.index.esm.js +0 -1
  77. package/dist/633.index.js +0 -1
  78. package/dist/967.index.esm.js +0 -1
  79. package/dist/967.index.js +0 -1
  80. package/dist/index.esm.js +0 -1
  81. package/dist/index.js +0 -1
@@ -0,0 +1,860 @@
1
+ /**
2
+ * TaroViz 主题系统 - 扩展版
3
+ * 提供图表主题配置和自定义主题功能
4
+ */
5
+
6
+ // ============================================================================
7
+ // 类型定义
8
+ // ============================================================================
9
+
10
+ /**
11
+ * 内置主题类型
12
+ */
13
+ export type BuiltinTheme =
14
+ | 'default'
15
+ | 'light'
16
+ | 'dark'
17
+ | 'vintage'
18
+ | 'macarons'
19
+ | 'roma'
20
+ | 'shine'
21
+ | 'infographic'
22
+ | 'westeros'
23
+ | 'walden'
24
+ | 'chalk'
25
+ | 'purple-passion'
26
+ | 'blue-green'
27
+ | 'golden'
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
+ }
75
+
76
+ /**
77
+ * 主题配置选项
78
+ */
79
+ export interface ThemeOptions {
80
+ /** 主题名称/键名 */
81
+ theme?: BuiltinTheme | Record<string, unknown>;
82
+
83
+ /** 是否启用深色模式 */
84
+ darkMode?: boolean;
85
+
86
+ /** 主题模式 */
87
+ mode?: ThemeMode;
88
+
89
+ /** 颜色列表 */
90
+ colors?: string[];
91
+
92
+ /** 背景色 */
93
+ backgroundColor?: string;
94
+
95
+ /** 背景渐变 */
96
+ backgroundGradient?: ThemeGradient;
97
+
98
+ /** 文本颜色 */
99
+ textColor?: string;
100
+
101
+ /** 次要文本颜色 */
102
+ textColorSecondary?: string;
103
+
104
+ /** 边框颜色 */
105
+ borderColor?: string;
106
+
107
+ /** 分割线颜色 */
108
+ dividerColor?: string;
109
+
110
+ /** 字体 */
111
+ fontFamily?: string;
112
+
113
+ /** 标题字体 */
114
+ fontFamilyTitle?: string;
115
+
116
+ /** 正文字体 */
117
+ fontFamilyBody?: string;
118
+
119
+ /** 主题名称(显示用) */
120
+ name?: string;
121
+
122
+ /** 主题描述 */
123
+ description?: string;
124
+
125
+ /** 主题作者 */
126
+ author?: string;
127
+
128
+ /** 主题版本 */
129
+ version?: string;
130
+
131
+ /** 主题类型 */
132
+ type?: ThemeMode;
133
+
134
+ /** 主题标签 */
135
+ tags?: string[];
136
+
137
+ /** 效果配置 */
138
+ effects?: ThemeEffects;
139
+
140
+ /** 图表特定配置 */
141
+ chart?: ChartThemeConfig;
142
+ }
143
+
144
+ /**
145
+ * 图表主题配置
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
+
224
+ const themeRegistry = new Map<string, ThemeOptions>();
225
+
226
+ // ============================================================================
227
+ // 内置主题定义
228
+ // ============================================================================
229
+
230
+ /** 默认主题 */
231
+ export const defaultTheme: ThemeOptions = {
232
+ theme: 'default',
233
+ name: 'Default',
234
+ description: '简洁现代的默认主题',
235
+ type: 'light',
236
+ mode: 'light',
237
+ darkMode: false,
238
+ tags: ['modern', 'clean', 'default'],
239
+ colors: [
240
+ '#5470c6',
241
+ '#91cc75',
242
+ '#fac858',
243
+ '#ee6666',
244
+ '#73c0de',
245
+ '#3ba272',
246
+ '#fc8452',
247
+ '#9a60b4',
248
+ '#ea7ccc',
249
+ ],
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
+ },
279
+ };
280
+
281
+ /** 深色主题 */
282
+ export const darkTheme: ThemeOptions = {
283
+ theme: 'dark',
284
+ name: 'Dark',
285
+ description: '优雅的深色主题,适合夜间使用',
286
+ type: 'dark',
287
+ mode: 'dark',
288
+ darkMode: true,
289
+ tags: ['dark', 'night', 'modern'],
290
+ colors: [
291
+ '#4992ff',
292
+ '#7cffb2',
293
+ '#fddd60',
294
+ '#ff6e76',
295
+ '#58d9f9',
296
+ '#05c091',
297
+ '#ff9f7f',
298
+ '#8d48e3',
299
+ '#dd79ff',
300
+ ],
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
+ },
330
+ };
331
+
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',
381
+ darkMode: false,
382
+ tags: ['glass', 'modern', 'minimal', 'light'],
383
+ colors: [
384
+ '#667eea',
385
+ '#764ba2',
386
+ '#f093fb',
387
+ '#f5576c',
388
+ '#4facfe',
389
+ '#00f2fe',
390
+ '#43e97b',
391
+ '#38f9d7',
392
+ '#fa709a',
393
+ ],
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
+ },
420
+ };
421
+
422
+ /** Pastel 粉彩主题 */
423
+ export const pastelTheme: ThemeOptions = {
424
+ theme: 'pastel',
425
+ name: 'Pastel',
426
+ description: '柔和粉彩配色,温馨舒适',
427
+ type: 'light',
428
+ mode: 'light',
429
+ darkMode: false,
430
+ tags: ['pastel', 'soft', 'gentle', 'light'],
431
+ colors: [
432
+ '#ffb3ba',
433
+ '#ffdfba',
434
+ '#ffffba',
435
+ '#baffc9',
436
+ '#bae1ff',
437
+ '#f0b3ff',
438
+ '#b3fff0',
439
+ '#ffb3d9',
440
+ '#d9ffb3',
441
+ ],
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
+ },
456
+ };
457
+
458
+ /** Sunset 日落主题 */
459
+ export const sunsetTheme: ThemeOptions = {
460
+ theme: 'sunset',
461
+ name: 'Sunset',
462
+ description: '温暖日落渐变,夕阳余晖',
463
+ type: 'light',
464
+ mode: 'light',
465
+ darkMode: false,
466
+ tags: ['sunset', 'warm', 'gradient', 'light'],
467
+ colors: [
468
+ '#ff6b6b',
469
+ '#feca57',
470
+ '#ff9ff3',
471
+ '#54a0ff',
472
+ '#5f27cd',
473
+ '#ff9f43',
474
+ '#ee5a24',
475
+ '#009432',
476
+ '#f368e0',
477
+ ],
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
+ },
495
+ };
496
+
497
+ /** Ocean 海洋主题 */
498
+ export const oceanTheme: ThemeOptions = {
499
+ theme: 'ocean',
500
+ name: 'Ocean',
501
+ description: '深邃海洋蓝,宁静清新',
502
+ type: 'light',
503
+ mode: 'light',
504
+ darkMode: false,
505
+ tags: ['ocean', 'blue', 'calm', 'light'],
506
+ colors: [
507
+ '#0077b6',
508
+ '#00b4d8',
509
+ '#90e0ef',
510
+ '#caf0f8',
511
+ '#03045e',
512
+ '#023e8a',
513
+ '#0096c7',
514
+ '#48cae4',
515
+ '#ade8f4',
516
+ ],
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
+ },
533
+ };
534
+
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',
585
+ darkMode: false,
586
+ tags: ['retro', 'vintage', 'nostalgic', 'light'],
587
+ colors: [
588
+ '#d63031',
589
+ '#e17055',
590
+ '#fdcb6e',
591
+ '#00b894',
592
+ '#0984e3',
593
+ '#6c5ce7',
594
+ '#e84393',
595
+ '#00cec9',
596
+ '#fab1a0',
597
+ ],
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
+ },
608
+ };
609
+
610
+ /** Elegant 雅致主题 */
611
+ export const elegantTheme: ThemeOptions = {
612
+ theme: 'elegant',
613
+ name: 'Elegant',
614
+ description: '低调雅致风格,精致品味',
615
+ type: 'light',
616
+ mode: 'light',
617
+ darkMode: false,
618
+ tags: ['elegant', 'minimal', 'sophisticated', 'light'],
619
+ colors: [
620
+ '#2c3e50',
621
+ '#34495e',
622
+ '#7f8c8d',
623
+ '#95a5a6',
624
+ '#bdc3c7',
625
+ '#ecf0f1',
626
+ '#1abc9c',
627
+ '#16a085',
628
+ '#3498db',
629
+ ],
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
+ },
641
+ };
642
+
643
+ // ============================================================================
644
+ // 主题管理函数
645
+ // ============================================================================
646
+
647
+ /**
648
+ * 获取主题配置
649
+ * @param options 自定义选项
650
+ * @returns 合并后的主题配置
651
+ */
652
+ export function getTheme(options?: Partial<ThemeOptions>): ThemeOptions {
653
+ if (!options) {
654
+ return defaultTheme;
655
+ }
656
+
657
+ let baseTheme: ThemeOptions;
658
+ if (options.theme && typeof options.theme === 'string') {
659
+ const registeredTheme = themeRegistry.get(options.theme);
660
+ if (registeredTheme) {
661
+ baseTheme = registeredTheme;
662
+ } else {
663
+ baseTheme = options.darkMode ? darkTheme : defaultTheme;
664
+ }
665
+ } else {
666
+ baseTheme = options.darkMode ? darkTheme : defaultTheme;
667
+ }
668
+
669
+ return { ...baseTheme, ...options };
670
+ }
671
+
672
+ /**
673
+ * 注册主题
674
+ * @param name 主题名称
675
+ * @param theme 主题配置
676
+ */
677
+ export function registerTheme(name: string, theme: ThemeOptions): void {
678
+ themeRegistry.set(name, { ...theme, name });
679
+ }
680
+
681
+ /**
682
+ * 获取已注册的主题列表
683
+ * @returns 主题列表
684
+ */
685
+ export function getRegisteredThemes(): ThemeOptions[] {
686
+ return Array.from(themeRegistry.values());
687
+ }
688
+
689
+ /**
690
+ * 获取指定主题
691
+ * @param name 主题名称
692
+ * @returns 主题配置
693
+ */
694
+ export function getThemeByName(name: string): ThemeOptions | undefined {
695
+ return themeRegistry.get(name);
696
+ }
697
+
698
+ /**
699
+ * 删除主题
700
+ * @param name 主题名称
701
+ */
702
+ export function unregisterTheme(name: string): void {
703
+ themeRegistry.delete(name);
704
+ }
705
+
706
+ /**
707
+ * 动态切换主题
708
+ * @param theme 主题名称或主题配置
709
+ * @param callback 切换完成后的回调函数
710
+ * @returns 主题配置
711
+ */
712
+ export function switchTheme(theme: string | ThemeOptions, callback?: () => void): ThemeOptions {
713
+ let themeConfig: ThemeOptions;
714
+
715
+ if (typeof theme === 'string') {
716
+ const registeredTheme = themeRegistry.get(theme);
717
+ themeConfig = registeredTheme || defaultTheme;
718
+ } else {
719
+ themeConfig = theme;
720
+ if (theme.name) {
721
+ registerTheme(theme.name, theme);
722
+ }
723
+ }
724
+
725
+ // 触发主题切换事件
726
+ if (typeof window !== 'undefined') {
727
+ window.dispatchEvent(new CustomEvent('themeChange', { detail: themeConfig }));
728
+ }
729
+
730
+ callback?.();
731
+
732
+ return themeConfig;
733
+ }
734
+
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
+ // ============================================================================
839
+
840
+ export default {
841
+ defaultTheme,
842
+ darkTheme,
843
+ neonTheme,
844
+ glassTheme,
845
+ pastelTheme,
846
+ sunsetTheme,
847
+ oceanTheme,
848
+ cyberTheme,
849
+ retroTheme,
850
+ elegantTheme,
851
+ getTheme,
852
+ registerTheme,
853
+ getRegisteredThemes,
854
+ getThemeByName,
855
+ unregisterTheme,
856
+ switchTheme,
857
+ getThemesByTag,
858
+ getLightThemes,
859
+ getDarkThemes,
860
+ };