@agions/taroviz 1.11.5 → 2.0.3

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 (118) hide show
  1. package/CHANGELOG.md +245 -0
  2. package/README.md +31 -46
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/vendors.js +1 -1
  5. package/dist/cjs/vendors~echarts.js +1 -1
  6. package/dist/esm/index.js +1 -14270
  7. package/dist/esm/vendors.js +1 -16770
  8. package/dist/esm/vendors~echarts.js +1 -59417
  9. package/package.json +10 -15
  10. package/src/adapters/h5/index.ts +38 -38
  11. package/src/adapters/index.ts +32 -34
  12. package/src/adapters/types.ts +23 -55
  13. package/src/charts/boxplot/types.ts +2 -2
  14. package/src/charts/common/BaseChartWrapper.tsx +9 -7
  15. package/src/charts/createChartComponent.tsx +9 -21
  16. package/src/charts/createOptionChartComponent.tsx +32 -0
  17. package/src/charts/funnel/__tests__/index.test.tsx +99 -0
  18. package/src/charts/funnel/index.tsx +64 -0
  19. package/src/charts/funnel/types.ts +6 -0
  20. package/src/charts/graph/__tests__/index.test.tsx +116 -0
  21. package/src/charts/graph/index.tsx +70 -0
  22. package/src/charts/graph/types.ts +6 -0
  23. package/src/charts/heatmap/__tests__/index.test.tsx +139 -0
  24. package/src/charts/heatmap/index.tsx +107 -0
  25. package/src/charts/heatmap/types.ts +6 -0
  26. package/src/charts/index.ts +47 -57
  27. package/src/charts/liquid/__tests__/index.test.tsx +52 -0
  28. package/src/charts/liquid/index.tsx +7 -133
  29. package/src/charts/liquid/types.ts +6 -6
  30. package/src/charts/parallel/types.ts +3 -3
  31. package/src/charts/radar/__tests__/index.test.tsx +210 -0
  32. package/src/charts/radar/index.tsx +147 -0
  33. package/src/charts/radar/types.ts +13 -0
  34. package/src/charts/sankey/__tests__/index.test.tsx +124 -0
  35. package/src/charts/sankey/index.tsx +70 -0
  36. package/src/charts/sankey/types.ts +6 -0
  37. package/src/charts/tree/__tests__/index.test.tsx +71 -0
  38. package/src/charts/tree/index.tsx +1 -1
  39. package/src/charts/tree/types.ts +8 -8
  40. package/src/charts/types.ts +208 -106
  41. package/src/charts/wordcloud/__tests__/index.test.tsx +106 -0
  42. package/src/charts/wordcloud/index.tsx +79 -0
  43. package/src/charts/wordcloud/types.ts +6 -0
  44. package/src/components/DataFilter/index.tsx +7 -6
  45. package/src/core/animation/types.ts +6 -6
  46. package/src/core/components/Annotation.tsx +6 -6
  47. package/src/core/components/BaseChart.tsx +97 -133
  48. package/src/core/components/LazyChart.tsx +3 -8
  49. package/src/core/components/hooks/index.ts +6 -2
  50. package/src/core/components/hooks/usePerformance.ts +8 -2
  51. package/src/core/components/hooks/useVirtualScroll.ts +2 -1
  52. package/src/core/types/common.ts +2 -1
  53. package/src/core/types/platform.ts +1 -0
  54. package/src/core/utils/__tests__/deepClone.test.ts +317 -0
  55. package/src/core/utils/__tests__/index.test.ts +2 -1
  56. package/src/core/utils/chartInstances.ts +13 -0
  57. package/src/core/utils/common.ts +20 -36
  58. package/src/core/utils/deepClone.ts +114 -0
  59. package/src/core/utils/download.ts +22 -28
  60. package/src/core/utils/drillDown.ts +1 -0
  61. package/src/core/utils/events.ts +12 -0
  62. package/src/core/utils/export/ExportUtils.ts +2 -1
  63. package/src/core/utils/format.ts +44 -0
  64. package/src/core/utils/index.ts +18 -159
  65. package/src/core/utils/merge.ts +25 -0
  66. package/src/core/utils/performance/PerformanceAnalyzer.ts +3 -1
  67. package/src/core/utils/performance/hooks.ts +7 -0
  68. package/src/core/utils/performance/index.ts +2 -0
  69. package/src/{hooks → core/utils/performance}/useAnimation.ts +6 -5
  70. package/src/{hooks → core/utils/performance}/useDataZoom.ts +7 -2
  71. package/src/{hooks → core/utils/performance}/usePerformance.ts +39 -39
  72. package/src/{hooks → core/utils/performance}/usePerformanceHooks.ts +39 -39
  73. package/src/core/utils/runtime.ts +190 -0
  74. package/src/editor/components/ThemeSelector.tsx +3 -3
  75. package/src/hooks/chartConnectHelpers.ts +6 -0
  76. package/src/hooks/index.ts +54 -626
  77. package/src/hooks/types.ts +27 -0
  78. package/src/hooks/useChartAutoResize.ts +73 -0
  79. package/src/hooks/useChartConnect.ts +5 -1
  80. package/src/hooks/useChartDownload.ts +1 -1
  81. package/src/hooks/useChartHistory.ts +1 -3
  82. package/src/hooks/useChartInit.ts +59 -0
  83. package/src/hooks/useChartOptions.ts +259 -0
  84. package/src/hooks/useChartPerformance.ts +109 -0
  85. package/src/hooks/useChartSelection.ts +23 -12
  86. package/src/hooks/useChartTheme.ts +51 -0
  87. package/src/hooks/useDataTransform.ts +19 -4
  88. package/src/index.ts +5 -10
  89. package/src/react-dom.d.ts +3 -3
  90. package/src/themes/index.ts +30 -855
  91. package/src/themes/palettes/blue-green.ts +13 -0
  92. package/src/themes/palettes/chalk.ts +13 -0
  93. package/src/themes/palettes/cyber.ts +44 -0
  94. package/src/themes/palettes/dark.ts +52 -0
  95. package/src/themes/palettes/default.ts +52 -0
  96. package/src/themes/palettes/elegant.ts +34 -0
  97. package/src/themes/palettes/forest.ts +13 -0
  98. package/src/themes/palettes/glass.ts +49 -0
  99. package/src/themes/palettes/golden.ts +13 -0
  100. package/src/themes/palettes/neon.ts +43 -0
  101. package/src/themes/palettes/ocean.ts +39 -0
  102. package/src/themes/palettes/pastel.ts +37 -0
  103. package/src/themes/palettes/purple-passion.ts +13 -0
  104. package/src/themes/palettes/retro.ts +33 -0
  105. package/src/themes/palettes/sunset.ts +40 -0
  106. package/src/themes/palettes/walden.ts +13 -0
  107. package/src/themes/registry.ts +184 -0
  108. package/src/themes/types.ts +213 -0
  109. package/src/core/utils/codeGenerator/CodeGenerator.ts +0 -669
  110. package/src/core/utils/codeGenerator/index.ts +0 -13
  111. package/src/core/utils/codeGenerator/types.ts +0 -198
  112. package/src/core/utils/configGenerator/ConfigGenerator.ts +0 -583
  113. package/src/core/utils/configGenerator/index.ts +0 -13
  114. package/src/core/utils/configGenerator/types.ts +0 -449
  115. package/src/core/utils/debug/DebugPanel.tsx +0 -640
  116. package/src/core/utils/debug/debugger.ts +0 -322
  117. package/src/core/utils/debug/index.ts +0 -21
  118. package/src/core/utils/debug/types.ts +0 -142
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Unified runtime detection for TaroViz
3
+ *
4
+ * Consolidates environment detection logic that was previously duplicated
5
+ * between core/utils/common.ts and adapters/index.ts.
6
+ */
7
+
8
+ /** Mini-app platform subtypes */
9
+ export type MiniAppType =
10
+ | 'weapp'
11
+ | 'alipay'
12
+ | 'swan'
13
+ | 'tt'
14
+ | 'qq'
15
+ | 'jd'
16
+ | 'dd'
17
+ | 'kwai'
18
+ | 'qywx'
19
+ | 'lark';
20
+
21
+ /** Unified runtime information */
22
+ export interface RuntimeInfo {
23
+ platform: 'browser' | 'node' | 'miniapp' | 'react-native' | 'unknown';
24
+ miniAppType?: MiniAppType;
25
+ isBrowser: boolean;
26
+ isNode: boolean;
27
+ isMiniApp: boolean;
28
+ isReactNative: boolean;
29
+ }
30
+
31
+ /** Cached runtime result — detection only runs once */
32
+ let cachedRuntime: RuntimeInfo | null = null;
33
+
34
+ /**
35
+ * Reset the cached runtime info (useful for testing).
36
+ */
37
+ export function resetRuntimeCache(): void {
38
+ cachedRuntime = null;
39
+ }
40
+
41
+ function makeResult(
42
+ platform: RuntimeInfo['platform'],
43
+ opts: Partial<Pick<RuntimeInfo, 'miniAppType'>> = {}
44
+ ): RuntimeInfo {
45
+ const isMiniApp = platform === 'miniapp';
46
+ const result: RuntimeInfo = {
47
+ platform,
48
+ isBrowser: platform === 'browser',
49
+ isNode: platform === 'node',
50
+ isMiniApp,
51
+ isReactNative: platform === 'react-native',
52
+ };
53
+ if (opts.miniAppType) {
54
+ result.miniAppType = opts.miniAppType;
55
+ }
56
+ cachedRuntime = result;
57
+ return result;
58
+ }
59
+
60
+ /** Safe access to global mini-app objects */
61
+ function getGlobalObj(): Record<string, unknown> {
62
+ if (typeof window !== 'undefined') return window as unknown as Record<string, unknown>;
63
+ if (typeof globalThis !== 'undefined') return globalThis as unknown as Record<string, unknown>;
64
+ return {};
65
+ }
66
+
67
+ function hasGetSystemInfoSync(key: string): boolean {
68
+ const g = getGlobalObj();
69
+ const obj = g[key];
70
+ return (
71
+ typeof obj !== 'undefined' &&
72
+ typeof (obj as Record<string, unknown>)?.getSystemInfoSync === 'function'
73
+ );
74
+ }
75
+
76
+ /**
77
+ * Detect the current runtime environment.
78
+ *
79
+ * Combines detection logic from:
80
+ * - src/core/utils/common.ts (isBrowser, isNode, isReactNative, isMiniApp)
81
+ * - src/adapters/index.ts (detectPlatform with getSystemInfoSync checks)
82
+ *
83
+ * Results are cached after the first call.
84
+ */
85
+ export function detectRuntime(): RuntimeInfo {
86
+ if (cachedRuntime) return cachedRuntime;
87
+
88
+ const g = getGlobalObj();
89
+
90
+ // --- Mini-app detection (order matters: more specific checks first) ---
91
+
92
+ // Enterprise WeChat must be checked before regular WeChat
93
+ const wx = g['wx'] as Record<string, unknown> | undefined;
94
+ if (typeof wx !== 'undefined' && wx?.qy) {
95
+ return makeResult('miniapp', { miniAppType: 'qywx' });
96
+ }
97
+
98
+ if (hasGetSystemInfoSync('wx')) {
99
+ return makeResult('miniapp', { miniAppType: 'weapp' });
100
+ }
101
+
102
+ if (hasGetSystemInfoSync('my')) {
103
+ return makeResult('miniapp', { miniAppType: 'alipay' });
104
+ }
105
+
106
+ if (hasGetSystemInfoSync('swan')) {
107
+ return makeResult('miniapp', { miniAppType: 'swan' });
108
+ }
109
+
110
+ if (hasGetSystemInfoSync('tt')) {
111
+ // Lark (Feishu) runs on the TT runtime but with appName === 'lark'
112
+ const ttObj = g['tt'] as Record<string, unknown> | undefined;
113
+ const env = ttObj?.env as Record<string, unknown> | undefined;
114
+ const isLark = env?.appName === 'lark';
115
+ return makeResult('miniapp', { miniAppType: isLark ? 'lark' : 'tt' });
116
+ }
117
+
118
+ if (hasGetSystemInfoSync('qq')) {
119
+ return makeResult('miniapp', { miniAppType: 'qq' });
120
+ }
121
+
122
+ if (hasGetSystemInfoSync('jd')) {
123
+ return makeResult('miniapp', { miniAppType: 'jd' });
124
+ }
125
+
126
+ if (hasGetSystemInfoSync('dd')) {
127
+ return makeResult('miniapp', { miniAppType: 'dd' });
128
+ }
129
+
130
+ // Kwai / Kuaishou: presence of ks global
131
+ if (typeof g['ks'] !== 'undefined') {
132
+ return makeResult('miniapp', { miniAppType: 'kwai' });
133
+ }
134
+
135
+ // --- Browser detection ---
136
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
137
+ return makeResult('browser');
138
+ }
139
+
140
+ // --- Node.js detection ---
141
+ try {
142
+ const proc = (globalThis as Record<string, unknown>).process as
143
+ | Record<string, unknown>
144
+ | undefined;
145
+ if (
146
+ typeof proc !== 'undefined' &&
147
+ proc.versions &&
148
+ (proc.versions as Record<string, unknown>).node &&
149
+ Object.prototype.toString.call(proc) === '[object process]'
150
+ ) {
151
+ return makeResult('node');
152
+ }
153
+ } catch {
154
+ // ignore
155
+ }
156
+
157
+ // --- React Native detection ---
158
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
159
+ return makeResult('react-native');
160
+ }
161
+
162
+ return makeResult('unknown');
163
+ }
164
+
165
+ /**
166
+ * 检测当前环境(简易版,向后兼容)
167
+ * @returns 环境信息
168
+ */
169
+ export function getEnvironment() {
170
+ const isServer = typeof window === 'undefined';
171
+ const isClient = !isServer;
172
+
173
+ // 使用类型断言解决wx和my未定义的问题
174
+ const win = window as Window & { wx?: unknown; my?: unknown };
175
+ const isWeapp =
176
+ typeof win.wx !== 'undefined' &&
177
+ typeof (win.wx as { getSystemInfoSync?: unknown })?.getSystemInfoSync === 'function';
178
+ const isAlipay =
179
+ typeof win.my !== 'undefined' &&
180
+ typeof (win.my as { getSystemInfoSync?: unknown })?.getSystemInfoSync === 'function';
181
+ const isWeb = isClient && !isWeapp && !isAlipay;
182
+
183
+ return {
184
+ isServer,
185
+ isClient,
186
+ isWeapp,
187
+ isAlipay,
188
+ isWeb,
189
+ };
190
+ }
@@ -54,13 +54,13 @@ const ThemeSelector: React.FC<ThemeSelectorProps> = ({
54
54
  padding: '8px 16px',
55
55
  border: '2px dashed #e0e0e0',
56
56
  borderRadius: '4px',
57
- backgroundColor: '#f5f5f5',
58
- color: '#333333',
57
+ backgroundColor: '#fafafa',
58
+ color: '#999999',
59
59
  cursor: disabled ? 'not-allowed' : 'pointer',
60
60
  opacity: disabled ? 0.6 : 1,
61
61
  }}
62
62
  >
63
- + 新主题
63
+ + 新建主题
64
64
  </button>
65
65
  </div>
66
66
  </div>
@@ -1,3 +1,4 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1
2
  /**
2
3
  * useChartConnect 辅助函数
3
4
  * 将 useChartConnect 中的逻辑拆分为独立函数,提高代码可维护性
@@ -45,14 +46,17 @@ export type EventHandlersMap = Map<string, Map<ConnectEventType, EventHandler>>;
45
46
  */
46
47
  export function createConnectHandler(
47
48
  sourceId: string,
49
+
48
50
  eventType: ConnectEventType,
49
51
  disabled: boolean,
52
+
50
53
  eventFilter: ((eventType: ConnectEventType, params: unknown) => boolean) | undefined,
51
54
  chartsRef: React.MutableRefObject<Map<string, ChartConnectItem>>,
52
55
  optionsRef: React.MutableRefObject<{
53
56
  onConnect?: (
54
57
  sourceId: string,
55
58
  targetId: string,
59
+
56
60
  payload: { eventType: ConnectEventType; params: unknown }
57
61
  ) => void;
58
62
  }>
@@ -85,6 +89,7 @@ export function createConnectHandler(
85
89
  */
86
90
  export function dispatchToOthers(
87
91
  sourceId: string,
92
+
88
93
  eventType: ConnectEventType,
89
94
  params: unknown,
90
95
  chartsRef: React.MutableRefObject<Map<string, ChartConnectItem>>
@@ -311,6 +316,7 @@ export function disconnectAllCharts(
311
316
  */
312
317
  export function dispatchConnectEvent(
313
318
  sourceId: string,
319
+
314
320
  payload: { eventType: ConnectEventType; params: unknown } | undefined,
315
321
  disabled: boolean,
316
322
  chartsRef: React.MutableRefObject<Map<string, ChartConnectItem>>,