@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,655 @@
1
+ /**
2
+ * TaroViz 代码示例生成器
3
+ * 用于生成不同框架和导入类型的代码示例
4
+ */
5
+
6
+ import { EChartsOption } from '../../types';
7
+
8
+ import {
9
+ CodeGeneratorOptions,
10
+ CodeGeneratorResult,
11
+ CodeExampleTemplate,
12
+ CodeGeneratorEventType,
13
+ CodeGeneratorEventHandler,
14
+ FrameworkType,
15
+ ImportType,
16
+ ThemeType,
17
+ } from './types';
18
+
19
+ /**
20
+ * 代码示例生成器类
21
+ */
22
+ export class CodeGenerator {
23
+ private static instance: CodeGenerator | null = null;
24
+ private eventHandlers: Map<CodeGeneratorEventType, CodeGeneratorEventHandler[]> = new Map();
25
+ private templates: Map<string, CodeExampleTemplate> = new Map();
26
+
27
+ /**
28
+ * 私有构造函数,使用单例模式
29
+ */
30
+ private constructor() {
31
+ // 初始化内置模板
32
+ this.initBuiltinTemplates();
33
+ }
34
+
35
+ /**
36
+ * 获取单例实例
37
+ */
38
+ public static getInstance(): CodeGenerator {
39
+ if (!CodeGenerator.instance) {
40
+ CodeGenerator.instance = new CodeGenerator();
41
+ }
42
+ return CodeGenerator.instance;
43
+ }
44
+
45
+ /**
46
+ * 注册事件处理器
47
+ */
48
+ public on(eventType: CodeGeneratorEventType, handler: CodeGeneratorEventHandler): void {
49
+ if (!this.eventHandlers.has(eventType)) {
50
+ this.eventHandlers.set(eventType, []);
51
+ }
52
+ this.eventHandlers.get(eventType)?.push(handler);
53
+ }
54
+
55
+ /**
56
+ * 移除事件处理器
57
+ */
58
+ public off(eventType: CodeGeneratorEventType, handler: CodeGeneratorEventHandler): void {
59
+ const handlers = this.eventHandlers.get(eventType);
60
+ if (handlers) {
61
+ const index = handlers.indexOf(handler);
62
+ if (index > -1) {
63
+ handlers.splice(index, 1);
64
+ }
65
+ }
66
+ }
67
+
68
+ /**
69
+ * 触发事件
70
+ */
71
+ private emit(eventType: CodeGeneratorEventType, data?: any): void {
72
+ const handlers = this.eventHandlers.get(eventType);
73
+ handlers?.forEach((handler) => {
74
+ try {
75
+ handler({ type: eventType, data });
76
+ } catch (error) {
77
+ console.error('Error in code generator event handler:', error);
78
+ }
79
+ });
80
+ }
81
+
82
+ /**
83
+ * 初始化内置模板
84
+ */
85
+ private initBuiltinTemplates(): void {
86
+ // React ESM TypeScript 模板
87
+ this.registerTemplate({
88
+ name: 'react-esm-ts',
89
+ description: 'React ESM TypeScript 代码示例模板',
90
+ frameworks: ['react'],
91
+ content: `import React from 'react';
92
+ import { BaseChart } from '@agions/taroviz';
93
+ import { EChartsOption } from '@agions/taroviz/types';
94
+
95
+ const { componentName } = options;
96
+ const chartId = options.chartId || 'chart';
97
+
98
+ const option: EChartsOption = {
99
+ title: {
100
+ text: '图表示例'
101
+ },
102
+ tooltip: {
103
+ trigger: 'axis'
104
+ },
105
+ legend: {
106
+ data: ['系列1', '系列2']
107
+ },
108
+ xAxis: {
109
+ type: 'category',
110
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
111
+ },
112
+ yAxis: {
113
+ type: 'value'
114
+ },
115
+ series: [
116
+ {
117
+ name: '系列1',
118
+ type: 'line',
119
+ data: [120, 200, 150, 80, 70, 110, 130]
120
+ },
121
+ {
122
+ name: '系列2',
123
+ type: 'line',
124
+ data: [220, 182, 191, 234, 290, 330, 310]
125
+ }
126
+ ]
127
+ };
128
+
129
+ const {componentName} = () => {
130
+ return (
131
+ <div style={{ width: '100%', height: '400px' }}>
132
+ <BaseChart
133
+ chartId={chartId}
134
+ option={option}
135
+ />
136
+ </div>
137
+ );
138
+ };
139
+
140
+ export default {componentName};`,
141
+ variables: ['componentName', 'chartId', 'option'],
142
+ });
143
+
144
+ // React ESM JavaScript 模板
145
+ this.registerTemplate({
146
+ name: 'react-esm-js',
147
+ description: 'React ESM JavaScript 代码示例模板',
148
+ frameworks: ['react'],
149
+ content: `import React from 'react';
150
+ import { BaseChart } from '@agions/taroviz';
151
+
152
+ const { componentName } = options;
153
+ const chartId = options.chartId || 'chart';
154
+
155
+ const option = {
156
+ title: {
157
+ text: '图表示例'
158
+ },
159
+ tooltip: {
160
+ trigger: 'axis'
161
+ },
162
+ legend: {
163
+ data: ['系列1', '系列2']
164
+ },
165
+ xAxis: {
166
+ type: 'category',
167
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
168
+ },
169
+ yAxis: {
170
+ type: 'value'
171
+ },
172
+ series: [
173
+ {
174
+ name: '系列1',
175
+ type: 'line',
176
+ data: [120, 200, 150, 80, 70, 110, 130]
177
+ },
178
+ {
179
+ name: '系列2',
180
+ type: 'line',
181
+ data: [220, 182, 191, 234, 290, 330, 310]
182
+ }
183
+ ]
184
+ };
185
+
186
+ const {componentName} = () => {
187
+ return (
188
+ <div style={{ width: '100%', height: '400px' }}>
189
+ <BaseChart
190
+ chartId={chartId}
191
+ option={option}
192
+ />
193
+ </div>
194
+ );
195
+ };
196
+
197
+ export default {componentName};`,
198
+ variables: ['componentName', 'chartId', 'option'],
199
+ });
200
+
201
+ // Vue ESM TypeScript 模板
202
+ this.registerTemplate({
203
+ name: 'vue-esm-ts',
204
+ description: 'Vue ESM TypeScript 代码示例模板',
205
+ frameworks: ['vue'],
206
+ content: `<template>
207
+ <div style="width: 100%; height: 400px;">
208
+ <BaseChart :chart-id="chartId" :option="option" />
209
+ </div>
210
+ </template>
211
+
212
+ <script setup lang="ts">
213
+ import { ref } from 'vue';
214
+ import { BaseChart } from '@agions/taroviz';
215
+ import { EChartsOption } from '@agions/taroviz/types';
216
+
217
+ const chartId = options.chartId || 'chart';
218
+
219
+ const option: EChartsOption = ref({
220
+ title: {
221
+ text: '图表示例'
222
+ },
223
+ tooltip: {
224
+ trigger: 'axis'
225
+ },
226
+ legend: {
227
+ data: ['系列1', '系列2']
228
+ },
229
+ xAxis: {
230
+ type: 'category',
231
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
232
+ },
233
+ yAxis: {
234
+ type: 'value'
235
+ },
236
+ series: [
237
+ {
238
+ name: '系列1',
239
+ type: 'line',
240
+ data: [120, 200, 150, 80, 70, 110, 130]
241
+ },
242
+ {
243
+ name: '系列2',
244
+ type: 'line',
245
+ data: [220, 182, 191, 234, 290, 330, 310]
246
+ }
247
+ ]
248
+ });
249
+ </script>`,
250
+ variables: ['chartId', 'option'],
251
+ });
252
+
253
+ // Vue ESM JavaScript 模板
254
+ this.registerTemplate({
255
+ name: 'vue-esm-js',
256
+ description: 'Vue ESM JavaScript 代码示例模板',
257
+ frameworks: ['vue'],
258
+ content: `<template>
259
+ <div style="width: 100%; height: 400px;">
260
+ <BaseChart :chart-id="chartId" :option="option" />
261
+ </div>
262
+ </template>
263
+
264
+ <script setup>
265
+ import { ref } from 'vue';
266
+ import { BaseChart } from '@agions/taroviz';
267
+
268
+ const chartId = options.chartId || 'chart';
269
+
270
+ const option = ref({
271
+ title: {
272
+ text: '图表示例'
273
+ },
274
+ tooltip: {
275
+ trigger: 'axis'
276
+ },
277
+ legend: {
278
+ data: ['系列1', '系列2']
279
+ },
280
+ xAxis: {
281
+ type: 'category',
282
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
283
+ },
284
+ yAxis: {
285
+ type: 'value'
286
+ },
287
+ series: [
288
+ {
289
+ name: '系列1',
290
+ type: 'line',
291
+ data: [120, 200, 150, 80, 70, 110, 130]
292
+ },
293
+ {
294
+ name: '系列2',
295
+ type: 'line',
296
+ data: [220, 182, 191, 234, 290, 330, 310]
297
+ }
298
+ ]
299
+ });
300
+ </script>`,
301
+ variables: ['chartId', 'option'],
302
+ });
303
+
304
+ // Vanilla ESM TypeScript 模板
305
+ this.registerTemplate({
306
+ name: 'vanilla-esm-ts',
307
+ description: 'Vanilla ESM TypeScript 代码示例模板',
308
+ frameworks: ['vanilla'],
309
+ content: `import { BaseChart } from '@agions/taroviz';
310
+ import { EChartsOption } from '@agions/taroviz/types';
311
+
312
+ const chartId = options.chartId || 'chart';
313
+ const container = document.getElementById(chartId);
314
+
315
+ if (!container) {
316
+ throw new Error('Chart container not found');
317
+ }
318
+
319
+ const option: EChartsOption = {
320
+ title: {
321
+ text: '图表示例'
322
+ },
323
+ tooltip: {
324
+ trigger: 'axis'
325
+ },
326
+ legend: {
327
+ data: ['系列1', '系列2']
328
+ },
329
+ xAxis: {
330
+ type: 'category',
331
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
332
+ },
333
+ yAxis: {
334
+ type: 'value'
335
+ },
336
+ series: [
337
+ {
338
+ name: '系列1',
339
+ type: 'line',
340
+ data: [120, 200, 150, 80, 70, 110, 130]
341
+ },
342
+ {
343
+ name: '系列2',
344
+ type: 'line',
345
+ data: [220, 182, 191, 234, 290, 330, 310]
346
+ }
347
+ ]
348
+ };
349
+
350
+ // 创建图表实例
351
+ const chart = new BaseChart({
352
+ chartId,
353
+ option,
354
+ container
355
+ });
356
+
357
+ // 渲染图表
358
+ chart.render();
359
+
360
+ // 导出图表实例
361
+ export default chart;`,
362
+ variables: ['chartId', 'option'],
363
+ });
364
+
365
+ // Vanilla ESM JavaScript 模板
366
+ this.registerTemplate({
367
+ name: 'vanilla-esm-js',
368
+ description: 'Vanilla ESM JavaScript 代码示例模板',
369
+ frameworks: ['vanilla'],
370
+ content: `import { BaseChart } from '@agions/taroviz';
371
+
372
+ const chartId = options.chartId || 'chart';
373
+ const container = document.getElementById(chartId);
374
+
375
+ if (!container) {
376
+ throw new Error('Chart container not found');
377
+ }
378
+
379
+ const option = {
380
+ title: {
381
+ text: '图表示例'
382
+ },
383
+ tooltip: {
384
+ trigger: 'axis'
385
+ },
386
+ legend: {
387
+ data: ['系列1', '系列2']
388
+ },
389
+ xAxis: {
390
+ type: 'category',
391
+ data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
392
+ },
393
+ yAxis: {
394
+ type: 'value'
395
+ },
396
+ series: [
397
+ {
398
+ name: '系列1',
399
+ type: 'line',
400
+ data: [120, 200, 150, 80, 70, 110, 130]
401
+ },
402
+ {
403
+ name: '系列2',
404
+ type: 'line',
405
+ data: [220, 182, 191, 234, 290, 330, 310]
406
+ }
407
+ ]
408
+ };
409
+
410
+ // 创建图表实例
411
+ const chart = new BaseChart({
412
+ chartId,
413
+ option,
414
+ container
415
+ });
416
+
417
+ // 渲染图表
418
+ chart.render();
419
+
420
+ // 导出图表实例
421
+ export default chart;`,
422
+ variables: ['chartId', 'option'],
423
+ });
424
+ }
425
+
426
+ /**
427
+ * 注册模板
428
+ */
429
+ public registerTemplate(template: CodeExampleTemplate): void {
430
+ this.templates.set(template.name, template);
431
+ }
432
+
433
+ /**
434
+ * 获取模板
435
+ */
436
+ public getTemplate(name: string): CodeExampleTemplate | undefined {
437
+ return this.templates.get(name);
438
+ }
439
+
440
+ /**
441
+ * 获取所有模板
442
+ */
443
+ public getAllTemplates(): CodeExampleTemplate[] {
444
+ return Array.from(this.templates.values());
445
+ }
446
+
447
+ /**
448
+ * 根据框架获取模板
449
+ */
450
+ public getTemplatesByFramework(framework: FrameworkType): CodeExampleTemplate[] {
451
+ return Array.from(this.templates.values()).filter((template) =>
452
+ template.frameworks.includes(framework)
453
+ );
454
+ }
455
+
456
+ /**
457
+ * 删除模板
458
+ */
459
+ public removeTemplate(name: string): void {
460
+ this.templates.delete(name);
461
+ }
462
+
463
+ /**
464
+ * 生成代码示例
465
+ */
466
+ public generate(option: EChartsOption, options: CodeGeneratorOptions): CodeGeneratorResult {
467
+ try {
468
+ // 触发生成开始事件
469
+ this.emit(CodeGeneratorEventType.GENERATE_START, { option, options });
470
+
471
+ // 应用模板
472
+ const generatedCode = this.generateCodeFromTemplate(option, options);
473
+
474
+ // 生成结果
475
+ const result: CodeGeneratorResult = {
476
+ code: generatedCode,
477
+ language: options.useTypeScript ? 'typescript' : 'javascript',
478
+ framework: options.framework,
479
+ importType: options.importType || 'esm',
480
+ theme: options.theme || 'light',
481
+ generatedAt: Date.now(),
482
+ extension: this.getFileExtension(options),
483
+ };
484
+
485
+ // 触发生成完成事件
486
+ this.emit(CodeGeneratorEventType.GENERATE_COMPLETE, result);
487
+
488
+ return result;
489
+ } catch (error) {
490
+ // 触发生成失败事件
491
+ this.emit(CodeGeneratorEventType.GENERATE_ERROR, { error });
492
+ throw error;
493
+ }
494
+ }
495
+
496
+ /**
497
+ * 从模板生成代码
498
+ */
499
+ private generateCodeFromTemplate(option: EChartsOption, options: CodeGeneratorOptions): string {
500
+ // 获取模板
501
+ const templateName = this.getTemplateName(options);
502
+ const template = this.getTemplate(templateName);
503
+
504
+ if (!template) {
505
+ throw new Error(`Template not found: ${templateName}`);
506
+ }
507
+
508
+ // 触发模板应用事件
509
+ this.emit(CodeGeneratorEventType.TEMPLATE_APPLY, { template, option, options });
510
+
511
+ // 替换模板变量
512
+ let code = template.content;
513
+
514
+ // 替换组件名称
515
+ const componentName = options.componentName || 'ChartComponent';
516
+ code = code.replace(/\{componentName\}/g, componentName);
517
+
518
+ // 替换图表ID
519
+ const chartId = options.chartId || 'chart';
520
+ code = code.replace(/\{chartId\}/g, chartId);
521
+
522
+ // 替换选项
523
+ const optionStr = JSON.stringify(option, null, 2);
524
+ code = code.replace(/\{\s*option\s*\}/g, optionStr);
525
+
526
+ // 处理导入类型
527
+ code = this.processImportType(code, options.importType || 'esm');
528
+
529
+ // 处理主题
530
+ code = this.processTheme(code, options.theme || 'light');
531
+
532
+ // 处理样式
533
+ if (!options.includeStyles) {
534
+ code = this.removeStyles(code);
535
+ }
536
+
537
+ // 处理数据
538
+ if (!options.includeData) {
539
+ code = this.removeData(code);
540
+ }
541
+
542
+ // 处理注释
543
+ if (!options.includeComments) {
544
+ code = this.removeComments(code);
545
+ }
546
+
547
+ return code;
548
+ }
549
+
550
+ /**
551
+ * 获取模板名称
552
+ */
553
+ private getTemplateName(options: CodeGeneratorOptions): string {
554
+ const framework = options.framework;
555
+ const importType = options.importType || 'esm';
556
+ const useTypeScript = options.useTypeScript || false;
557
+
558
+ return `${framework}-${importType}-${useTypeScript ? 'ts' : 'js'}`;
559
+ }
560
+
561
+ /**
562
+ * 获取文件扩展名
563
+ */
564
+ private getFileExtension(options: CodeGeneratorOptions): string {
565
+ const useTypeScript = options.useTypeScript || false;
566
+ const framework = options.framework;
567
+
568
+ if (framework === 'vue') {
569
+ return 'vue';
570
+ }
571
+
572
+ return useTypeScript ? 'tsx' : 'jsx';
573
+ }
574
+
575
+ /**
576
+ * 处理导入类型
577
+ */
578
+ private processImportType(code: string, importType: ImportType): string {
579
+ switch (importType) {
580
+ case 'cjs':
581
+ return code.replace(/import\s+([^\s]+)\s+from\s+([^;]+);/g, 'const $1 = require($2);');
582
+ case 'umd':
583
+ return code.replace(
584
+ /import\s+([^\s]+)\s+from\s+([^;]+);/g,
585
+ 'const $1 = window.TaroViz.$1;'
586
+ );
587
+ default:
588
+ return code;
589
+ }
590
+ }
591
+
592
+ /**
593
+ * 处理主题
594
+ */
595
+ private processTheme(code: string, theme: ThemeType): string {
596
+ // 添加主题相关的样式或配置
597
+ if (theme === 'dark') {
598
+ return code.replace(
599
+ /style={{([^}]+)}}/g,
600
+ "style={{$1, backgroundColor: '#1a1a1a', color: '#ffffff'}}"
601
+ );
602
+ }
603
+ return code;
604
+ }
605
+
606
+ /**
607
+ * 移除样式
608
+ */
609
+ private removeStyles(code: string): string {
610
+ return code.replace(/style={{[^}]+}}/g, '');
611
+ }
612
+
613
+ /**
614
+ * 移除数据
615
+ */
616
+ private removeData(code: string): string {
617
+ return code.replace(/\s*data:\s*\[[^\]]+\]/g, 'data: []');
618
+ }
619
+
620
+ /**
621
+ * 移除注释
622
+ */
623
+ private removeComments(code: string): string {
624
+ // 移除单行注释
625
+ code = code.replace(/\/\/.*$/gm, '');
626
+ // 移除多行注释
627
+ code = code.replace(/\/\*[\s\S]*?\*\//g, '');
628
+ // 移除空行
629
+ code = code.replace(/^\s*\n/gm, '');
630
+ return code;
631
+ }
632
+
633
+ /**
634
+ * 生成完整的代码示例
635
+ */
636
+ public generateCompleteExample(option: EChartsOption, options: CodeGeneratorOptions): string {
637
+ const result = this.generate(option, options);
638
+ return result.code;
639
+ }
640
+
641
+ /**
642
+ * 生成代码片段
643
+ */
644
+ public generateSnippet(option: EChartsOption, options: CodeGeneratorOptions): string {
645
+ const result = this.generate(option, options);
646
+ return result.code;
647
+ }
648
+
649
+ /**
650
+ * 重置实例
651
+ */
652
+ public static resetInstance(): void {
653
+ CodeGenerator.instance = null;
654
+ }
655
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * TaroViz 代码示例生成器入口
3
+ */
4
+
5
+ // 导出类型定义
6
+ export * from './types';
7
+
8
+ // 导出代码示例生成器类
9
+ export { CodeGenerator } from './CodeGenerator';
10
+
11
+ // 导出默认实例
12
+ import { CodeGenerator } from './CodeGenerator';
13
+ export const codeGenerator = CodeGenerator.getInstance();