react-ai-renderer 0.1.2 → 0.1.4

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/dist/{MermaidRenderer-a25ae84f.js → MermaidRenderer-62cbf217.js} +1 -1
  2. package/dist/{MermaidRenderer-d8836800.js → MermaidRenderer-680adac3.js} +1 -1
  3. package/dist/{index-415b51ad.js → index-543584d8.js} +237 -135
  4. package/dist/{index-bb96fdaf.js → index-58ab9759.js} +237 -135
  5. package/dist/index.d.ts +30 -9
  6. package/dist/index.es.js +1 -1
  7. package/dist/index.js +1 -1
  8. package/package.json +1 -1
  9. package/dist/MermaidRenderer-0ef71453.js +0 -170
  10. package/dist/MermaidRenderer-0ef71453.js.map +0 -1
  11. package/dist/MermaidRenderer-13e4a89a.js +0 -172
  12. package/dist/MermaidRenderer-13e4a89a.js.map +0 -1
  13. package/dist/MermaidRenderer-321bfe50.js +0 -170
  14. package/dist/MermaidRenderer-321bfe50.js.map +0 -1
  15. package/dist/MermaidRenderer-325a9dee.js +0 -170
  16. package/dist/MermaidRenderer-325a9dee.js.map +0 -1
  17. package/dist/MermaidRenderer-4bae11d6.js +0 -170
  18. package/dist/MermaidRenderer-4bae11d6.js.map +0 -1
  19. package/dist/MermaidRenderer-6237d7da.js +0 -170
  20. package/dist/MermaidRenderer-6237d7da.js.map +0 -1
  21. package/dist/MermaidRenderer-653a4dab.js +0 -172
  22. package/dist/MermaidRenderer-653a4dab.js.map +0 -1
  23. package/dist/MermaidRenderer-67edae8e.js +0 -172
  24. package/dist/MermaidRenderer-67edae8e.js.map +0 -1
  25. package/dist/MermaidRenderer-6f071d8e.js +0 -170
  26. package/dist/MermaidRenderer-6f071d8e.js.map +0 -1
  27. package/dist/MermaidRenderer-75832c15.js +0 -172
  28. package/dist/MermaidRenderer-75832c15.js.map +0 -1
  29. package/dist/MermaidRenderer-7cb138d1.js +0 -170
  30. package/dist/MermaidRenderer-7cb138d1.js.map +0 -1
  31. package/dist/MermaidRenderer-8a8fb725.js +0 -172
  32. package/dist/MermaidRenderer-8a8fb725.js.map +0 -1
  33. package/dist/MermaidRenderer-91a0a7d8.js +0 -170
  34. package/dist/MermaidRenderer-91a0a7d8.js.map +0 -1
  35. package/dist/MermaidRenderer-9ff856f3.js +0 -172
  36. package/dist/MermaidRenderer-9ff856f3.js.map +0 -1
  37. package/dist/MermaidRenderer-a25ae84f.js.map +0 -1
  38. package/dist/MermaidRenderer-c3014102.js +0 -172
  39. package/dist/MermaidRenderer-c3014102.js.map +0 -1
  40. package/dist/MermaidRenderer-c664aa66.js +0 -170
  41. package/dist/MermaidRenderer-c664aa66.js.map +0 -1
  42. package/dist/MermaidRenderer-d1518f28.js +0 -172
  43. package/dist/MermaidRenderer-d1518f28.js.map +0 -1
  44. package/dist/MermaidRenderer-d7545a7e.js +0 -172
  45. package/dist/MermaidRenderer-d7545a7e.js.map +0 -1
  46. package/dist/MermaidRenderer-d8836800.js.map +0 -1
  47. package/dist/MermaidRenderer-d9c8351a.js +0 -172
  48. package/dist/MermaidRenderer-d9c8351a.js.map +0 -1
  49. package/dist/MermaidRenderer-dc0ac92e.js +0 -170
  50. package/dist/MermaidRenderer-dc0ac92e.js.map +0 -1
  51. package/dist/MermaidRenderer-e549ab85.js +0 -172
  52. package/dist/MermaidRenderer-e549ab85.js.map +0 -1
  53. package/dist/MermaidRenderer-e5d81a6f.js +0 -172
  54. package/dist/MermaidRenderer-e5d81a6f.js.map +0 -1
  55. package/dist/MermaidRenderer-e82f36e4.js +0 -172
  56. package/dist/MermaidRenderer-e82f36e4.js.map +0 -1
  57. package/dist/MermaidRenderer-f04366c1.js +0 -170
  58. package/dist/MermaidRenderer-f04366c1.js.map +0 -1
  59. package/dist/MermaidRenderer-f6473da3.js +0 -170
  60. package/dist/MermaidRenderer-f6473da3.js.map +0 -1
  61. package/dist/MermaidRenderer-f82d0d11.js +0 -170
  62. package/dist/MermaidRenderer-f82d0d11.js.map +0 -1
  63. package/dist/index-02f4473f.js +0 -1313
  64. package/dist/index-02f4473f.js.map +0 -1
  65. package/dist/index-172582eb.js +0 -1294
  66. package/dist/index-172582eb.js.map +0 -1
  67. package/dist/index-1d051ba8.js +0 -1286
  68. package/dist/index-1d051ba8.js.map +0 -1
  69. package/dist/index-283b43ef.js +0 -1285
  70. package/dist/index-283b43ef.js.map +0 -1
  71. package/dist/index-2d979ad5.js +0 -1314
  72. package/dist/index-2d979ad5.js.map +0 -1
  73. package/dist/index-349401d2.js +0 -1288
  74. package/dist/index-349401d2.js.map +0 -1
  75. package/dist/index-398258c5.js +0 -1314
  76. package/dist/index-398258c5.js.map +0 -1
  77. package/dist/index-3cf82be4.js +0 -1287
  78. package/dist/index-3cf82be4.js.map +0 -1
  79. package/dist/index-3de28f18.js +0 -1319
  80. package/dist/index-3de28f18.js.map +0 -1
  81. package/dist/index-415b51ad.js.map +0 -1
  82. package/dist/index-4592abf8.js +0 -1311
  83. package/dist/index-4592abf8.js.map +0 -1
  84. package/dist/index-4edeb553.js +0 -1313
  85. package/dist/index-4edeb553.js.map +0 -1
  86. package/dist/index-534d3bce.js +0 -1312
  87. package/dist/index-534d3bce.js.map +0 -1
  88. package/dist/index-6ceb7256.js +0 -1287
  89. package/dist/index-6ceb7256.js.map +0 -1
  90. package/dist/index-7e8dc866.js +0 -1304
  91. package/dist/index-7e8dc866.js.map +0 -1
  92. package/dist/index-896de550.js +0 -1313
  93. package/dist/index-896de550.js.map +0 -1
  94. package/dist/index-8dbf398a.js +0 -1313
  95. package/dist/index-8dbf398a.js.map +0 -1
  96. package/dist/index-922bbd30.js +0 -1339
  97. package/dist/index-922bbd30.js.map +0 -1
  98. package/dist/index-a5a2c748.js +0 -1288
  99. package/dist/index-a5a2c748.js.map +0 -1
  100. package/dist/index-abed2ed7.js +0 -1286
  101. package/dist/index-abed2ed7.js.map +0 -1
  102. package/dist/index-ae31bd04.js +0 -1312
  103. package/dist/index-ae31bd04.js.map +0 -1
  104. package/dist/index-b0cab34f.js +0 -1287
  105. package/dist/index-b0cab34f.js.map +0 -1
  106. package/dist/index-bb96fdaf.js.map +0 -1
  107. package/dist/index-c0acef6b.js +0 -1330
  108. package/dist/index-c0acef6b.js.map +0 -1
  109. package/dist/index-c6ab333d.js +0 -1293
  110. package/dist/index-c6ab333d.js.map +0 -1
  111. package/dist/index-d4f12a68.js +0 -1287
  112. package/dist/index-d4f12a68.js.map +0 -1
  113. package/dist/index-e07ca144.js +0 -1320
  114. package/dist/index-e07ca144.js.map +0 -1
  115. package/dist/index-fdaa9757.js +0 -1313
  116. package/dist/index-fdaa9757.js.map +0 -1
  117. package/dist/index.es.js.map +0 -1
  118. package/dist/index.js.map +0 -1
@@ -1,1320 +0,0 @@
1
- 'use strict';
2
-
3
- var React = require('react');
4
- var runtime = require('react/jsx-runtime');
5
- var RemarkMath = require('remark-math');
6
- var RemarkBreaks = require('remark-breaks');
7
- var RemarkGfm = require('remark-gfm');
8
- var mdx = require('@mdx-js/mdx');
9
- var RehypeKatex = require('rehype-katex');
10
- var RehypeHighlight = require('rehype-highlight');
11
-
12
- function _interopNamespaceDefault(e) {
13
- var n = Object.create(null);
14
- if (e) {
15
- Object.keys(e).forEach(function (k) {
16
- if (k !== 'default') {
17
- var d = Object.getOwnPropertyDescriptor(e, k);
18
- Object.defineProperty(n, k, d.get ? d : {
19
- enumerable: true,
20
- get: function () { return e[k]; }
21
- });
22
- }
23
- });
24
- }
25
- n.default = e;
26
- return Object.freeze(n);
27
- }
28
-
29
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
30
- var runtime__namespace = /*#__PURE__*/_interopNamespaceDefault(runtime);
31
-
32
- var MDXStreamingParser = /** @class */function () {
33
- function MDXStreamingParser(components) {
34
- // 将组件名称存储在Set中,而不是整个组件对象
35
- this.registeredComponents = new Set(components.map(function (c) {
36
- return c.name;
37
- }));
38
- this.messages = new Map();
39
- }
40
- // 检查组件是否已注册
41
- MDXStreamingParser.prototype.isComponentRegistered = function (name) {
42
- return this.registeredComponents.has(name);
43
- };
44
- MDXStreamingParser.prototype.parse = function (messageId, input) {
45
- var state = {
46
- position: 0,
47
- stack: [],
48
- buffer: ''
49
- };
50
- var result = [];
51
- var i = state.position;
52
- while (i < input.length) {
53
- var char = input[i];
54
- if (char === '<') {
55
- // Handle closing tags
56
- if (input[i + 1] === '/') {
57
- var closeTagEnd = input.indexOf('>', i);
58
- if (closeTagEnd === -1) {
59
- state.buffer += input.slice(i);
60
- break;
61
- }
62
- var tagName = input.slice(i + 2, closeTagEnd);
63
- // 检查组件是否已注册
64
- var isRegistered = this.isComponentRegistered(tagName);
65
- // 如果组件未注册,则作为文本处理
66
- if (!isRegistered) {
67
- state.buffer += input.slice(i, closeTagEnd + 1);
68
- i = closeTagEnd + 1;
69
- continue;
70
- }
71
- if (/^[A-Z][A-Za-z0-9]*$/.test(tagName)) {
72
- // Handle text content in the buffer
73
- var trimmedContent = state.buffer.trim();
74
- if (trimmedContent && state.stack.length > 0) {
75
- var currentComponent = state.stack[state.stack.length - 1];
76
- if (!currentComponent.children) {
77
- currentComponent.children = [];
78
- }
79
- if (typeof currentComponent.children === 'string') {
80
- currentComponent.children = [{
81
- type: "text",
82
- value: currentComponent.children
83
- }];
84
- }
85
- currentComponent.children.push({
86
- type: "text",
87
- value: trimmedContent
88
- });
89
- }
90
- state.buffer = '';
91
- state.stack.pop();
92
- i = closeTagEnd + 1;
93
- continue;
94
- }
95
- }
96
- // Handle opening tags
97
- var tagMatch = input.slice(i).match(/^<([A-Z][A-Za-z0-9]*)/);
98
- if (tagMatch) {
99
- // Handle accumulated text before the tag
100
- var componentName = tagMatch[1];
101
- // 检查组件是否已注册
102
- var isRegistered = this.isComponentRegistered(componentName);
103
- // 如果组件未注册,将整个标签作为文本处理
104
- if (!isRegistered) {
105
- state.buffer += input[i];
106
- i++;
107
- continue;
108
- }
109
- var trimmedText = state.buffer.trim();
110
- if (trimmedText && state.stack.length === 0) {
111
- result.push({
112
- type: "text",
113
- value: trimmedText
114
- });
115
- } else if (trimmedText && state.stack.length > 0) {
116
- var currentComponent = state.stack[state.stack.length - 1];
117
- if (!currentComponent.children) {
118
- currentComponent.children = [];
119
- }
120
- if (typeof currentComponent.children === 'string') {
121
- currentComponent.children = [{
122
- type: "text",
123
- value: currentComponent.children
124
- }];
125
- }
126
- currentComponent.children.push({
127
- type: "text",
128
- value: trimmedText
129
- });
130
- }
131
- state.buffer = '';
132
- // 动态解析标签形式,不再依赖预先注册的 selfClosing 属性
133
- var _a = this.parseComponentTag(input.slice(i)),
134
- props = _a.props,
135
- endIndex = _a.endIndex,
136
- selfClosing = _a.selfClosing;
137
- var component = {
138
- type: "component",
139
- value: componentName,
140
- props: props,
141
- selfClosing: selfClosing // 使用实际解析出的标签形式
142
- };
143
- if (!selfClosing) {
144
- state.stack.push(component);
145
- if (state.stack.length === 1) {
146
- result.push(component);
147
- } else {
148
- var parent_1 = state.stack[state.stack.length - 2];
149
- if (!parent_1.children || typeof parent_1.children === 'string') {
150
- parent_1.children = [];
151
- }
152
- parent_1.children.push(component);
153
- }
154
- } else {
155
- if (state.stack.length === 0) {
156
- result.push(component);
157
- } else {
158
- var parent_2 = state.stack[state.stack.length - 1];
159
- if (!parent_2.children || typeof parent_2.children === 'string') {
160
- parent_2.children = [];
161
- }
162
- parent_2.children.push(component);
163
- }
164
- }
165
- i += endIndex;
166
- char = input[i];
167
- continue;
168
- }
169
- }
170
- state.buffer += char;
171
- i++;
172
- }
173
- // Handle any remaining text in the buffer
174
- var finalText = state.buffer.trim();
175
- if (finalText && state.stack.length === 0) {
176
- if (finalText === '<') {
177
- result.push({
178
- type: "text",
179
- value: ''
180
- });
181
- } else {
182
- result.push({
183
- type: "text",
184
- value: finalText
185
- });
186
- }
187
- } else if (finalText && state.stack.length > 0) {
188
- var currentComponent = state.stack[state.stack.length - 1];
189
- if (!currentComponent.children) {
190
- currentComponent.children = [];
191
- }
192
- if (typeof currentComponent.children === 'string') {
193
- currentComponent.children = [{
194
- type: "text",
195
- value: currentComponent.children
196
- }];
197
- }
198
- currentComponent.children.push({
199
- type: "text",
200
- value: finalText
201
- });
202
- }
203
- state.position = i;
204
- return result;
205
- };
206
- MDXStreamingParser.prototype.findComponentClose = function (input, startIndex) {
207
- var depth = 1;
208
- var i = startIndex;
209
- var openclose = false; // 内嵌开闭标签要成对
210
- while (i < input.length) {
211
- if (input[i] === '/' && input[i + 1] === '>') {
212
- depth--;
213
- if (depth === 0) return i + 2;
214
- i += 2;
215
- } else if (input[i] === '<') {
216
- openclose = true;
217
- depth++;
218
- i++;
219
- } else if (input[i] === '>') {
220
- if (openclose) {
221
- openclose = false;
222
- depth--;
223
- }
224
- if (depth === 0) return i + 1;
225
- i++;
226
- } else {
227
- i++;
228
- }
229
- }
230
- return input.length;
231
- };
232
- MDXStreamingParser.prototype.parseComponentTag = function (input) {
233
- var props = {};
234
- var i = 0;
235
- // 跳过组件名
236
- while (i < input.length && input[i] !== ' ' && input[i] !== '>') i++;
237
- // 使用 parsePropsCommon 方法解析属性,该方法会返回标签形式信息
238
- var _a = this.parsePropsCommon(input),
239
- parsedProps = _a.props,
240
- endIndex = _a.endIndex,
241
- selfClosing = _a.selfClosing;
242
- Object.assign(props, parsedProps);
243
- return {
244
- props: props,
245
- endIndex: endIndex,
246
- selfClosing: selfClosing
247
- };
248
- };
249
- MDXStreamingParser.prototype.parsePropsCommon = function (input) {
250
- var props = {};
251
- var i = 0;
252
- var inQuote = false;
253
- var quoteChar = '';
254
- var bracketCount = 0;
255
- var selfClosing = false;
256
- // 跳过组件名
257
- while (i < input.length && input[i] !== ' ' && input[i] !== '>') i++;
258
- while (i < input.length) {
259
- var char = input[i];
260
- if (char === '"' || char === "'") {
261
- if (!inQuote) {
262
- inQuote = true;
263
- quoteChar = char;
264
- } else if (char === quoteChar && bracketCount === 0) {
265
- inQuote = false;
266
- }
267
- } else if (char === '{' && !inQuote) {
268
- bracketCount++;
269
- } else if (char === '}' && !inQuote) {
270
- bracketCount--;
271
- } else if (char === '/' && input[i + 1] === '>' && !inQuote && bracketCount === 0) {
272
- selfClosing = true;
273
- return {
274
- props: props,
275
- endIndex: i + 2,
276
- selfClosing: selfClosing
277
- };
278
- } else if (char === '>' && !inQuote && bracketCount === 0) {
279
- return {
280
- props: props,
281
- endIndex: i + 1,
282
- selfClosing: selfClosing
283
- };
284
- }
285
- if (char === '=' && !inQuote && bracketCount === 0) {
286
- var propName = '';
287
- var j = i - 1;
288
- while (j >= 0 && /[\w-]/.test(input[j])) {
289
- propName = input[j] + propName;
290
- j--;
291
- }
292
- var value = '';
293
- j = i + 1;
294
- if (input[j] === '{') {
295
- // 处理 JSON 值
296
- var startBracket = j;
297
- bracketCount = 1;
298
- j++;
299
- while (j < input.length && bracketCount > 0) {
300
- if (input[j] === '{') bracketCount++;
301
- if (input[j] === '}') bracketCount--;
302
- j++;
303
- }
304
- value = input.slice(startBracket + 1, j - 1);
305
- try {
306
- // 处理属性值中的模板字符串
307
- value = value.replace(/`([^`]*)`/g, function (match, p1) {
308
- return JSON.stringify(p1);
309
- });
310
- // 处理可能的对象字面量
311
- if (value.trim().startsWith('{')) {
312
- props[propName] = JSON.parse(value);
313
- } else {
314
- // 处理其他 JSON 值
315
- try {
316
- props[propName] = JSON.parse(value);
317
- } catch (_a) {
318
- // 如果不是有效的 JSON,保持原值
319
- props[propName] = value;
320
- }
321
- }
322
- } catch (e) {
323
- console.warn("Failed to parse prop value for ".concat(propName, ":"), value);
324
- props[propName] = value;
325
- }
326
- i = j;
327
- continue;
328
- } else if (input[j] === '"' || input[j] === "'") {
329
- // 处理字符串值
330
- var quote = input[j];
331
- j++;
332
- while (j < input.length && input[j] !== quote) {
333
- value += input[j];
334
- j++;
335
- }
336
- props[propName] = value;
337
- i = j + 1;
338
- continue;
339
- }
340
- }
341
- i++;
342
- }
343
- return {
344
- props: props,
345
- endIndex: i,
346
- selfClosing: selfClosing
347
- };
348
- };
349
- MDXStreamingParser.prototype.parsePropsSelfClosing = function (content) {
350
- var props = {};
351
- // 先找到当前标签的结束位置
352
- var endIndex = content.indexOf('/>');
353
- if (endIndex === -1) return props;
354
- // 只处理当前标签内的内容
355
- var tagContent = content.slice(0, endIndex);
356
- // 使用更精确的正则匹配属性
357
- var propRegex = /(\w+)=(?:"([^"]*)"|'([^']*)'|{([^}]*)})/g;
358
- var match;
359
- while ((match = propRegex.exec(tagContent)) !== null) {
360
- var propName = match[1];
361
- var value = void 0;
362
- if (match[2] !== undefined) {
363
- // 处理双引号值
364
- value = match[2];
365
- } else if (match[3] !== undefined) {
366
- // 处理单引号值
367
- value = match[3];
368
- } else if (match[4] !== undefined) {
369
- // 处理花括号值
370
- try {
371
- value = JSON.parse(match[4]);
372
- } catch (e) {
373
- value = match[4]; // 解析失败保留原始值
374
- }
375
- }
376
- props[propName] = value;
377
- }
378
- return props;
379
- };
380
- MDXStreamingParser.prototype.reset = function () {
381
- this.messages.clear();
382
- };
383
- return MDXStreamingParser;
384
- }();
385
-
386
- /******************************************************************************
387
- Copyright (c) Microsoft Corporation.
388
-
389
- Permission to use, copy, modify, and/or distribute this software for any
390
- purpose with or without fee is hereby granted.
391
-
392
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
393
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
394
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
395
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
396
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
397
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
398
- PERFORMANCE OF THIS SOFTWARE.
399
- ***************************************************************************** */
400
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
401
-
402
- var extendStatics = function(d, b) {
403
- extendStatics = Object.setPrototypeOf ||
404
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
405
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
406
- return extendStatics(d, b);
407
- };
408
-
409
- function __extends(d, b) {
410
- if (typeof b !== "function" && b !== null)
411
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
412
- extendStatics(d, b);
413
- function __() { this.constructor = d; }
414
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
415
- }
416
-
417
- var __assign = function() {
418
- __assign = Object.assign || function __assign(t) {
419
- for (var s, i = 1, n = arguments.length; i < n; i++) {
420
- s = arguments[i];
421
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
422
- }
423
- return t;
424
- };
425
- return __assign.apply(this, arguments);
426
- };
427
-
428
- function __rest(s, e) {
429
- var t = {};
430
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
431
- t[p] = s[p];
432
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
433
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
434
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
435
- t[p[i]] = s[p[i]];
436
- }
437
- return t;
438
- }
439
-
440
- function __awaiter(thisArg, _arguments, P, generator) {
441
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
442
- return new (P || (P = Promise))(function (resolve, reject) {
443
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
444
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
445
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
446
- step((generator = generator.apply(thisArg, _arguments || [])).next());
447
- });
448
- }
449
-
450
- function __generator(thisArg, body) {
451
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
452
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
453
- function verb(n) { return function (v) { return step([n, v]); }; }
454
- function step(op) {
455
- if (f) throw new TypeError("Generator is already executing.");
456
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
457
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
458
- if (y = 0, t) op = [op[0] & 2, t.value];
459
- switch (op[0]) {
460
- case 0: case 1: t = op; break;
461
- case 4: _.label++; return { value: op[1], done: false };
462
- case 5: _.label++; y = op[1]; op = [0]; continue;
463
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
464
- default:
465
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
466
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
467
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
468
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
469
- if (t[2]) _.ops.pop();
470
- _.trys.pop(); continue;
471
- }
472
- op = body.call(thisArg, _);
473
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
474
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
475
- }
476
- }
477
-
478
- function __values(o) {
479
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
480
- if (m) return m.call(o);
481
- if (o && typeof o.length === "number") return {
482
- next: function () {
483
- if (o && i >= o.length) o = void 0;
484
- return { value: o && o[i++], done: !o };
485
- }
486
- };
487
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
488
- }
489
-
490
- function __read(o, n) {
491
- var m = typeof Symbol === "function" && o[Symbol.iterator];
492
- if (!m) return o;
493
- var i = m.call(o), r, ar = [], e;
494
- try {
495
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
496
- }
497
- catch (error) { e = { error: error }; }
498
- finally {
499
- try {
500
- if (r && !r.done && (m = i["return"])) m.call(i);
501
- }
502
- finally { if (e) throw e.error; }
503
- }
504
- return ar;
505
- }
506
-
507
- function __spreadArray(to, from, pack) {
508
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
509
- if (ar || !(i in from)) {
510
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
511
- ar[i] = from[i];
512
- }
513
- }
514
- return to.concat(ar || Array.prototype.slice.call(from));
515
- }
516
-
517
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
518
- var e = new Error(message);
519
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
520
- };
521
-
522
- var CodeHighlight = function (_a) {
523
- var textContent = _a.textContent,
524
- _b = _a.language,
525
- language = _b === void 0 ? "txt" : _b,
526
- darkMode = _a.darkMode;
527
- var _c = __read(React.useState(false), 2),
528
- showCopy = _c[0],
529
- setShowCopy = _c[1];
530
- var copyToClipboard = function (text) {
531
- return __awaiter(void 0, void 0, void 0, function () {
532
- var textarea;
533
- return __generator(this, function (_a) {
534
- switch (_a.label) {
535
- case 0:
536
- _a.trys.push([0, 2,, 3]);
537
- return [4 /*yield*/, navigator.clipboard.writeText(text)];
538
- case 1:
539
- _a.sent();
540
- // 简单的复制成功提示
541
- alert('代码已复制到剪贴板');
542
- return [3 /*break*/, 3];
543
- case 2:
544
- _a.sent();
545
- textarea = document.createElement("textarea");
546
- textarea.value = text;
547
- document.body.appendChild(textarea);
548
- textarea.select();
549
- try {
550
- document.execCommand("copy");
551
- alert('代码已复制到剪贴板');
552
- } catch (error) {
553
- console.error("Fallback copy failed", error);
554
- }
555
- document.body.removeChild(textarea);
556
- return [3 /*break*/, 3];
557
- case 3:
558
- return [2 /*return*/];
559
- }
560
- });
561
- });
562
- };
563
- // 标准化语言名称,增强对 mermaid 语言的识别
564
- var normalizedLanguage = language.toLowerCase();
565
- // 检查是否为 mermaid 语言的变体
566
- if (normalizedLanguage.includes('mermaid')) {
567
- normalizedLanguage = "mermaid";
568
- }
569
- if (language === "mermaid") {
570
- // 动态导入 MermaidRenderer 组件
571
- var MermaidRenderer = /*#__PURE__*/React.lazy(function () {
572
- return Promise.resolve().then(function () { return require('./MermaidRenderer-d9c8351a.js'); }).catch(function () {
573
- return {
574
- default: function () {
575
- return /*#__PURE__*/runtime.jsx("div", {});
576
- }
577
- };
578
- });
579
- });
580
- return /*#__PURE__*/runtime.jsx(React.Suspense, {
581
- fallback: /*#__PURE__*/runtime.jsx("div", {}),
582
- children: /*#__PURE__*/runtime.jsx(MermaidRenderer, {
583
- chart: String(textContent)
584
- }, Date.now())
585
- });
586
- }
587
- // 简单的代码高亮样式
588
- var codeStyle = {
589
- backgroundColor: darkMode ? '#2d2d2d' : '#f5f5f5',
590
- color: darkMode ? '#f8f8f2' : '#333',
591
- padding: '12px',
592
- borderRadius: '4px',
593
- fontFamily: 'monospace',
594
- fontSize: '14px',
595
- lineHeight: '1.4',
596
- overflowX: 'auto',
597
- border: "1px solid ".concat(darkMode ? '#555' : '#ddd')
598
- };
599
- return /*#__PURE__*/runtime.jsxs("div", {
600
- style: {
601
- position: "relative"
602
- },
603
- children: [/*#__PURE__*/runtime.jsx("button", {
604
- style: {
605
- position: "absolute",
606
- right: "10px",
607
- top: "5px",
608
- zIndex: 1,
609
- background: darkMode ? "#555" : "#333",
610
- color: "#fff",
611
- border: "none",
612
- padding: "4px 8px",
613
- fontSize: "12px",
614
- cursor: "pointer",
615
- borderRadius: "4px"
616
- },
617
- onClick: function (e) {
618
- e.preventDefault();
619
- copyToClipboard(String(textContent));
620
- },
621
- onMouseEnter: function () {
622
- return setShowCopy(true);
623
- },
624
- onMouseLeave: function () {
625
- return setShowCopy(false);
626
- },
627
- children: showCopy ? "点击复制" : "复制"
628
- }), /*#__PURE__*/runtime.jsx("pre", {
629
- style: codeStyle,
630
- children: /*#__PURE__*/runtime.jsx("code", {
631
- children: String(textContent).replace(/\n$/, "")
632
- })
633
- })]
634
- });
635
- };
636
-
637
- var Think = function (_a) {
638
- var content = _a.content,
639
- children = _a.children;
640
- var thinkContent = content || children;
641
- if (!thinkContent) {
642
- return /*#__PURE__*/runtime.jsx("div", {});
643
- }
644
- return /*#__PURE__*/runtime.jsx("div", {
645
- style: {
646
- marginBottom: 12
647
- },
648
- children: /*#__PURE__*/runtime.jsxs("details", {
649
- open: true,
650
- children: [/*#__PURE__*/runtime.jsx("summary", {
651
- style: {
652
- fontWeight: 'bold',
653
- cursor: 'pointer',
654
- padding: '8px',
655
- backgroundColor: '#f0f0f0',
656
- borderRadius: '4px',
657
- marginBottom: '8px'
658
- },
659
- children: "\uD83E\uDDE0 AI \u601D\u8003\u8FC7\u7A0B"
660
- }), /*#__PURE__*/runtime.jsx("blockquote", {
661
- style: {
662
- borderLeft: '3px solid #2196f3',
663
- color: '#666',
664
- paddingLeft: 12,
665
- fontStyle: 'italic',
666
- marginBottom: 0,
667
- backgroundColor: '#f9f9f9',
668
- padding: '8px'
669
- },
670
- children: typeof thinkContent === 'string' ? decodeURIComponent(thinkContent) : thinkContent
671
- })]
672
- })
673
- });
674
- };
675
-
676
- var VideoComponent = function (_a) {
677
- _a.node;
678
- var props = __rest(_a, ["node"]);
679
- var videoNode = {
680
- props: {}
681
- };
682
- try {
683
- props.children.map(function (item) {
684
- if (item.props && item.type === 'source') {
685
- videoNode = item;
686
- }
687
- });
688
- } catch (e) {}
689
- return /*#__PURE__*/runtime.jsxs("video", {
690
- controls: true,
691
- ...props,
692
- children: [/*#__PURE__*/runtime.jsx("source", {
693
- src: videoNode.props.src || '',
694
- type: videoNode.props.type || 'video/mp4'
695
- }), "\u4F60\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301video\u6807\u7B7E"]
696
- });
697
- };
698
- // 音频组件
699
- var AudioComponent = function (_a) {
700
- _a.node;
701
- var props = __rest(_a, ["node"]);
702
- var audioNode = {
703
- props: {}
704
- };
705
- try {
706
- props.children.map(function (item) {
707
- if (item.props && item.type === 'source') {
708
- audioNode = item;
709
- }
710
- });
711
- } catch (e) {
712
- console.error('Error processing audio children:', e);
713
- }
714
- return /*#__PURE__*/runtime.jsxs("audio", {
715
- controls: true,
716
- ...props,
717
- children: [/*#__PURE__*/runtime.jsx("source", {
718
- src: audioNode.props.src || '',
719
- type: audioNode.props.type || 'audio/mpeg'
720
- }), "\u4F60\u7684\u6D4F\u89C8\u5668\u4E0D\u652F\u6301 audio \u6807\u7B7E"]
721
- });
722
- };
723
- // 代码组件
724
- var CodeComponent = function (props) {
725
- var children = props.children,
726
- className = props.className;
727
- props.node;
728
- var rest = __rest(props, ["children", "className", "node"]);
729
- var match = /language-(\w+)/.exec(className || "");
730
- String(children).replace(/\n$/, '');
731
- var extractText = function (children) {
732
- return React.Children.toArray(children).reduce(function (acc, child) {
733
- if (typeof child === 'string') {
734
- return acc + child;
735
- } else if (/*#__PURE__*/React.isValidElement(child) && child.props && child.props.children) {
736
- return acc + extractText(child.props.children);
737
- }
738
- return acc;
739
- }, '');
740
- };
741
- var content = extractText(children);
742
- // 增强语言检测逻辑,检查内容中是否包含mermaid特征
743
- var language = match ? match[1] : "txt";
744
- // 如果内容包含mermaid特征且语言未正确识别,则强制设置为mermaid
745
- if (!match || match[1] !== "mermaid") {
746
- var trimmedContent = content.trim();
747
- if (trimmedContent.startsWith('graph') || trimmedContent.startsWith('flowchart') || trimmedContent.startsWith('sequenceDiagram') || trimmedContent.startsWith('gantt') || trimmedContent.startsWith('classDiagram') || trimmedContent.startsWith('stateDiagram') || trimmedContent.startsWith('pie') || trimmedContent.startsWith('erDiagram') || trimmedContent.startsWith('journey') || trimmedContent.startsWith('requirementDiagram') || trimmedContent.startsWith('gitGraph')) {
748
- language = "mermaid";
749
- }
750
- }
751
- return language !== "txt" ? /*#__PURE__*/runtime.jsx(CodeHighlight, {
752
- ...rest,
753
- language: language,
754
- textContent: content,
755
- children: content
756
- }) : /*#__PURE__*/runtime.jsx("code", {
757
- className: className,
758
- ...props,
759
- children: content
760
- });
761
- };
762
- // 段落组件
763
- var PComponent = function (pProps) {
764
- return /*#__PURE__*/runtime.jsx("p", {
765
- ...pProps,
766
- dir: "auto"
767
- });
768
- };
769
- // 链接组件
770
- var AComponent = function (aProps) {
771
- var _a;
772
- var href = aProps.href || "";
773
- var isInternal = /^\/#/i.test(href);
774
- var target = isInternal ? "_self" : (_a = aProps.target) !== null && _a !== void 0 ? _a : "_blank";
775
- // 增强链接样式,使其更加明显
776
- var linkStyle = {
777
- color: '#1a73e8',
778
- fontWeight: '600',
779
- borderBottom: '2px solid #1a73e8',
780
- paddingBottom: '2px',
781
- transition: 'all 0.2s ease'
782
- };
783
- // 鼠标悬停效果
784
- var hoverStyle = {
785
- color: '#0d47a1',
786
- borderBottom: '2px solid #0d47a1',
787
- backgroundColor: 'rgba(26, 115, 232, 0.1)'
788
- };
789
- // 合并原有属性和新样式
790
- return /*#__PURE__*/runtime.jsx("a", {
791
- ...aProps,
792
- target: target,
793
- style: __assign(__assign({}, linkStyle), aProps.style),
794
- onMouseEnter: function (e) {
795
- var target = e.target;
796
- Object.assign(target.style, hoverStyle);
797
- aProps.onMouseEnter && aProps.onMouseEnter(e);
798
- },
799
- onMouseLeave: function (e) {
800
- var target = e.target;
801
- Object.assign(target.style, linkStyle);
802
- aProps.onMouseLeave && aProps.onMouseLeave(e);
803
- }
804
- });
805
- };
806
- // Pre 组件
807
- var PreComponent = function (props) {
808
- return /*#__PURE__*/runtime.jsx("div", {
809
- ...props
810
- });
811
- };
812
- var BuiltInComponents = {
813
- AC_DS_THINK: Think,
814
- pre: PreComponent,
815
- code: CodeComponent,
816
- p: PComponent,
817
- a: AComponent,
818
- video: VideoComponent,
819
- audio: AudioComponent
820
- };
821
-
822
- var ErrorBoundary = /** @class */function (_super) {
823
- __extends(ErrorBoundary, _super);
824
- function ErrorBoundary(props) {
825
- var _this = _super.call(this, props) || this;
826
- _this.state = {
827
- hasError: false
828
- };
829
- return _this;
830
- }
831
- ErrorBoundary.getDerivedStateFromError = function () {
832
- return {
833
- hasError: true
834
- };
835
- };
836
- ErrorBoundary.prototype.componentDidCatch = function (error, errorInfo) {
837
- // 可以在这里记录错误信息
838
- };
839
- ErrorBoundary.prototype.render = function () {
840
- if (this.state.hasError) {
841
- return /*#__PURE__*/runtime.jsx("div", {
842
- children: this.props.content
843
- });
844
- }
845
- return this.props.children;
846
- };
847
- return ErrorBoundary;
848
- }(React.Component);
849
-
850
- function MdxLayout(_a) {
851
- var children = _a.children;
852
- return /*#__PURE__*/runtime.jsx("div", {
853
- children: children
854
- });
855
- }
856
-
857
- var THINK_BEGIN_TAG = '<think>';
858
- var THINK_END_TAG = '</think>';
859
- var CUSTOMER_THINK_COMPONENT_DISPLAY = 'AC_DS_THINK';
860
- function fixMDXContent(content) {
861
- // 替换中文括号为英文括号
862
- return content.replace(/\\\[/g, '$$').replace(/\\\]/g, '$$')
863
- // 确保LaTeX公式正确转义
864
- .replace(/\\\(/g, '$').replace(/\\\)/g, '$');
865
- }
866
- function generateRandomName(length) {
867
- if (length === void 0) {
868
- length = 6;
869
- }
870
- var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
871
- var result = '';
872
- for (var i = 0; i < length; i++) {
873
- result += characters.charAt(Math.floor(Math.random() * characters.length));
874
- }
875
- return result;
876
- }
877
- function remarkThinkUpdate(content) {
878
- var thinkContent = '';
879
- var resultContent = '';
880
- var thinkBeginIndex = content.indexOf(THINK_BEGIN_TAG);
881
- var thinkEndIndex = content.lastIndexOf(THINK_END_TAG);
882
- if (thinkBeginIndex !== -1 && thinkEndIndex === -1) {
883
- // 有开始,无结束
884
- thinkContent = content.slice(THINK_BEGIN_TAG.length);
885
- thinkContent = "<".concat(CUSTOMER_THINK_COMPONENT_DISPLAY, " content=\"").concat(encodeURIComponent(thinkContent), "\" />");
886
- } else if (thinkBeginIndex !== -1 && thinkEndIndex !== -1) {
887
- // 有开始,有结束
888
- var anotherEndIndex = content.indexOf(THINK_END_TAG);
889
- if (anotherEndIndex !== thinkEndIndex) {
890
- thinkContent = content.slice(THINK_BEGIN_TAG.length, anotherEndIndex);
891
- resultContent = content.slice(thinkEndIndex + THINK_END_TAG.length);
892
- thinkContent = "<".concat(CUSTOMER_THINK_COMPONENT_DISPLAY, " content=\"").concat(encodeURIComponent(thinkContent), "\" />");
893
- } else {
894
- thinkContent = content.slice(THINK_BEGIN_TAG.length, thinkEndIndex);
895
- thinkContent = "<".concat(CUSTOMER_THINK_COMPONENT_DISPLAY, " content=\"").concat(encodeURIComponent(thinkContent), "\" />");
896
- resultContent = content.slice(thinkEndIndex + THINK_END_TAG.length);
897
- }
898
- } else if (thinkBeginIndex == -1) {
899
- resultContent = content;
900
- }
901
- return {
902
- thinkContent: thinkContent,
903
- resultContent: resultContent
904
- };
905
- }
906
-
907
- var renderTimer = null;
908
- // 辅助函数:格式化props
909
- function formatProps(props) {
910
- return Object.entries(props).map(function (_a) {
911
- var _b = __read(_a, 2),
912
- key = _b[0],
913
- value = _b[1];
914
- if (typeof value === 'string') {
915
- return "".concat(key, "=\"").concat(value, "\"");
916
- }
917
- try {
918
- value = JSON.stringify(value);
919
- } catch (e) {
920
- console.error('Error stringifying prop value:', e);
921
- }
922
- return "".concat(key, "={").concat(value, "}");
923
- }).join(' ');
924
- }
925
- function renderMdx(mdxContent, scope, registeredComponents) {
926
- return __awaiter(this, void 0, void 0, function () {
927
- var componentTagRegex, usedComponents, match, _registeredComponents, usedComponents_1, usedComponents_1_1, component, vf, XComponent, e_1;
928
- var e_2, _a;
929
- return __generator(this, function (_b) {
930
- switch (_b.label) {
931
- case 0:
932
- _b.trys.push([0, 3,, 4]);
933
- renderTimer && clearTimeout(renderTimer);
934
- componentTagRegex = /<([A-Z][a-zA-Z]*)\b/g;
935
- usedComponents = new Set();
936
- match = void 0;
937
- while ((match = componentTagRegex.exec(mdxContent)) !== null) {
938
- usedComponents.add(match[1]);
939
- }
940
- _registeredComponents = new Set(Object.keys(registeredComponents));
941
- try {
942
- for (usedComponents_1 = __values(usedComponents), usedComponents_1_1 = usedComponents_1.next(); !usedComponents_1_1.done; usedComponents_1_1 = usedComponents_1.next()) {
943
- component = usedComponents_1_1.value;
944
- if (!_registeredComponents.has(component)) {
945
- throw new Error("Component ".concat(component, " is used but not registered in the components object."));
946
- }
947
- }
948
- } catch (e_2_1) {
949
- e_2 = {
950
- error: e_2_1
951
- };
952
- } finally {
953
- try {
954
- if (usedComponents_1_1 && !usedComponents_1_1.done && (_a = usedComponents_1.return)) _a.call(usedComponents_1);
955
- } finally {
956
- if (e_2) throw e_2.error;
957
- }
958
- }
959
- return [4 /*yield*/, mdx.compile(mdxContent, {
960
- outputFormat: "function-body",
961
- remarkPlugins: [[RemarkMath, {
962
- strict: true
963
- }], RemarkGfm, RemarkBreaks],
964
- rehypePlugins: [[RehypeKatex], [RehypeHighlight, {
965
- detect: false,
966
- ignoreMissing: true,
967
- plainText: ['mermaid'] // 将mermaid作为纯文本处理,避免被错误高亮
968
- }]]
969
- })];
970
- case 1:
971
- vf = _b.sent();
972
- return [4 /*yield*/, mdx.run(vf, __assign(__assign(__assign({}, runtime__namespace), scope), {
973
- Fragment: MdxLayout
974
- }))];
975
- case 2:
976
- XComponent = _b.sent().default;
977
- return [2 /*return*/, /*#__PURE__*/React__namespace.createElement(XComponent, {
978
- components: registeredComponents,
979
- scope: scope
980
- })];
981
- case 3:
982
- e_1 = _b.sent();
983
- return [2 /*return*/, new Promise(function (resolve) {
984
- renderTimer = setTimeout(function () {
985
- console.log(e_1, 'e');
986
- console.log(mdxContent, 'mdxContent');
987
- resolve(/*#__PURE__*/React__namespace.createElement('div', {
988
- style: {
989
- backgroundColor: 'transparent'
990
- }
991
- }, mdxContent));
992
- clearTimeout(renderTimer); // 清理定时器
993
- }, 1000); // 1秒延迟
994
- })];
995
- case 4:
996
- return [2 /*return*/];
997
- }
998
- });
999
- });
1000
- }
1001
- // 递归解析组件的函数
1002
- function parseComponentRecursively(allComponentHandlers, item, scope) {
1003
- return __awaiter(this, void 0, void 0, function () {
1004
- var componentHandler, componentString_1, parsedChildren, props, propsString, childrenContent_1, parsedChildren_1, componentString;
1005
- return __generator(this, function (_a) {
1006
- switch (_a.label) {
1007
- case 0:
1008
- if (item.type === 'text') {
1009
- return [2 /*return*/, item.value];
1010
- }
1011
- if (!(item.type === 'component')) return [3 /*break*/, 8];
1012
- componentHandler = allComponentHandlers.find(function (c) {
1013
- return c.name === item.value;
1014
- });
1015
- if (!!componentHandler) return [3 /*break*/, 5];
1016
- componentString_1 = "<".concat(item.value);
1017
- if (item.props) {
1018
- componentString_1 += ' ' + Object.entries(item.props).map(function (_a) {
1019
- var _b = __read(_a, 2),
1020
- key = _b[0],
1021
- value = _b[1];
1022
- if (typeof value === 'string') {
1023
- return "".concat(key, "=\"").concat(value, "\"");
1024
- }
1025
- try {
1026
- return "".concat(key, "={").concat(JSON.stringify(value), "}");
1027
- } catch (e) {
1028
- return "".concat(key, "=\"[object Object]\"");
1029
- }
1030
- }).join(' ');
1031
- }
1032
- if (!item.selfClosing) return [3 /*break*/, 1];
1033
- componentString_1 += ' />';
1034
- return [3 /*break*/, 4];
1035
- case 1:
1036
- componentString_1 += '>';
1037
- if (!(item.children && Array.isArray(item.children))) return [3 /*break*/, 3];
1038
- return [4 /*yield*/, Promise.all(item.children.map(function (child) {
1039
- return parseComponentRecursively(allComponentHandlers, child, scope);
1040
- }))];
1041
- case 2:
1042
- parsedChildren = _a.sent();
1043
- componentString_1 += parsedChildren.join('');
1044
- _a.label = 3;
1045
- case 3:
1046
- componentString_1 += "</".concat(item.value, ">");
1047
- _a.label = 4;
1048
- case 4:
1049
- return [2 /*return*/, componentString_1];
1050
- case 5:
1051
- props = __assign(__assign({}, item.props), {
1052
- key: generateRandomName()
1053
- });
1054
- propsString = formatProps(props);
1055
- propsString += " scope={props.scope}";
1056
- childrenContent_1 = '';
1057
- if (!(item.children && Array.isArray(item.children))) return [3 /*break*/, 7];
1058
- return [4 /*yield*/, Promise.all(item.children.map(function (child) {
1059
- return parseComponentRecursively(allComponentHandlers, child, scope);
1060
- }))];
1061
- case 6:
1062
- parsedChildren_1 = _a.sent();
1063
- item.children.map(function (item, index) {
1064
- if (item.type === 'text') {
1065
- // 对包含特殊字符的文本进行转义处理,避免MDX解析错误
1066
- var textContent = parsedChildren_1[index];
1067
- if (typeof textContent === 'string' && (textContent.includes('{') || textContent.includes('}'))) {
1068
- // 使用 encodeURIComponent 编码内容,但需要在组件内部解码
1069
- childrenContent_1 += encodeURIComponent(textContent);
1070
- } else {
1071
- childrenContent_1 += textContent;
1072
- }
1073
- } else {
1074
- childrenContent_1 += parsedChildren_1[index];
1075
- }
1076
- });
1077
- _a.label = 7;
1078
- case 7:
1079
- // 调用组件的渲染钩子
1080
- if (componentHandler.onRender) {
1081
- componentHandler.onRender(item, scope);
1082
- }
1083
- componentString = componentHandler.selfClosing ? "<".concat(item.value, " ").concat(propsString, " />") : "\t\n<".concat(item.value, " ").concat(propsString, ">\n").concat(childrenContent_1, "\n</").concat(item.value, ">\t\n");
1084
- return [2 /*return*/, componentString];
1085
- case 8:
1086
- return [2 /*return*/, null];
1087
- }
1088
- });
1089
- });
1090
- }
1091
-
1092
- // 使用 WeakMap 作为缓存,避免重复检测相同组件类型
1093
- var componentDetectionCache = new WeakMap();
1094
- /**
1095
- * 检测组件是否为自闭合组件
1096
- * 通过检查组件是否接受 children 属性来判断
1097
- * @param component - 要检测的 React 组件
1098
- * @returns boolean - true 表示自闭合组件(不支持 children),false 表示非自闭合组件(支持 children)
1099
- */
1100
- function isSelfClosingComponent(component) {
1101
- // 首先检查缓存
1102
- if (componentDetectionCache.has(component)) {
1103
- return componentDetectionCache.get(component);
1104
- }
1105
- try {
1106
- // 对于函数组件,使用更可靠的方法检测
1107
- if (typeof component === 'function') {
1108
- // 优先检查组件的 propTypes(如果存在)
1109
- if ('propTypes' in component && component.propTypes) {
1110
- var propTypes = component.propTypes;
1111
- var hasChildrenPropType = 'children' in propTypes;
1112
- var result_1 = !hasChildrenPropType;
1113
- componentDetectionCache.set(component, result_1);
1114
- return result_1;
1115
- }
1116
- // 检查组件的 defaultProps(如果存在)
1117
- if ('defaultProps' in component && component.defaultProps) {
1118
- var defaultProps = component.defaultProps;
1119
- // 如果 defaultProps 中包含 children,则组件支持 children
1120
- if ('children' in defaultProps) {
1121
- componentDetectionCache.set(component, false);
1122
- return false;
1123
- }
1124
- }
1125
- // 检查函数签名(如果可用)
1126
- var componentString = component.toString();
1127
- // 移除注释和多余空格
1128
- var cleanString = componentString.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/.*$/gm, '').trim();
1129
- // 检查是否显式接受 children 参数
1130
- var hasChildrenDestructuring = /\(\s*\{[^}]*\bchildren\b[^}]*\}/.test(cleanString);
1131
- // 如果组件参数中明确包含 children,则认为是非自闭合组件
1132
- if (hasChildrenDestructuring) {
1133
- componentDetectionCache.set(component, false);
1134
- return false;
1135
- } else {
1136
- componentDetectionCache.set(component, true);
1137
- return true;
1138
- }
1139
- }
1140
- // 对于类组件,默认假设是非自闭合的
1141
- var result = false;
1142
- componentDetectionCache.set(component, result);
1143
- return result;
1144
- } catch (error) {
1145
- // 如果检测过程中出现错误,默认返回 false(非自闭合)
1146
- var result = false;
1147
- componentDetectionCache.set(component, result);
1148
- return result;
1149
- }
1150
- }
1151
-
1152
- function ReactAIRenderer(_a) {
1153
- var _this = this;
1154
- var content = _a.content,
1155
- _b = _a.scope,
1156
- scope = _b === void 0 ? {} : _b,
1157
- components = _a.components,
1158
- children = _a.children,
1159
- _c = _a.componentHandlers,
1160
- componentHandlers = _c === void 0 ? [] : _c;
1161
- content = content || children;
1162
- var allComponents = __assign(__assign({}, BuiltInComponents), components);
1163
- // 修复:确保 components 是一个对象后再使用 Object.entries
1164
- var allComponentHandlers = __spreadArray(__spreadArray([], __read(components ? Object.entries(components).filter(function (_a) {
1165
- var _b = __read(_a, 1),
1166
- name = _b[0];
1167
- return !componentHandlers.some(function (handler) {
1168
- return handler.name === name;
1169
- });
1170
- }).map(function (_a) {
1171
- var _b = __read(_a, 2),
1172
- name = _b[0],
1173
- component = _b[1];
1174
- var selfClosing = isSelfClosingComponent(component);
1175
- return {
1176
- component: component,
1177
- name: name,
1178
- selfClosing: selfClosing
1179
- };
1180
- }) : []), false), __read(componentHandlers), false);
1181
- var _d = __read(React.useState(null), 2),
1182
- component = _d[0],
1183
- setComponent = _d[1];
1184
- var parser = new MDXStreamingParser(allComponentHandlers);
1185
- var mdxContent = content;
1186
- React.useEffect(function () {
1187
- var parseMDX = function () {
1188
- return __awaiter(_this, void 0, void 0, function () {
1189
- var ThinkComponent, ResultComponent, _a, thinkContent, resultContent, parsedData, parsedComponents, finalComponent, i, _result, MDXComponent;
1190
- return __generator(this, function (_b) {
1191
- switch (_b.label) {
1192
- case 0:
1193
- ThinkComponent = null;
1194
- ResultComponent = null;
1195
- _a = remarkThinkUpdate(mdxContent), thinkContent = _a.thinkContent, resultContent = _a.resultContent;
1196
- if (!thinkContent) return [3 /*break*/, 2];
1197
- return [4 /*yield*/, renderMdx(thinkContent, scope, allComponents)];
1198
- case 1:
1199
- ThinkComponent = _b.sent();
1200
- _b.label = 2;
1201
- case 2:
1202
- if (!resultContent) return [3 /*break*/, 8];
1203
- resultContent = fixMDXContent(resultContent);
1204
- parsedData = parser.parse('magic', resultContent);
1205
- return [4 /*yield*/, Promise.all(parsedData.map(function (item) {
1206
- return parseComponentRecursively(allComponentHandlers, item, scope);
1207
- }))];
1208
- case 3:
1209
- parsedComponents = _b.sent();
1210
- finalComponent = [];
1211
- i = 0;
1212
- _b.label = 4;
1213
- case 4:
1214
- if (!(i < parsedComponents.length)) return [3 /*break*/, 7];
1215
- return [4 /*yield*/, renderMdx(parsedComponents[i], scope, allComponents)];
1216
- case 5:
1217
- _result = _b.sent();
1218
- finalComponent.push(_result);
1219
- _b.label = 6;
1220
- case 6:
1221
- i++;
1222
- return [3 /*break*/, 4];
1223
- case 7:
1224
- ResultComponent = /*#__PURE__*/runtime.jsx("div", {
1225
- children: finalComponent
1226
- });
1227
- _b.label = 8;
1228
- case 8:
1229
- MDXComponent = /*#__PURE__*/runtime.jsxs(React.Fragment, {
1230
- children: [ThinkComponent, ResultComponent]
1231
- });
1232
- setComponent(MDXComponent);
1233
- return [2 /*return*/];
1234
- }
1235
- });
1236
- });
1237
- };
1238
- parseMDX();
1239
- }, [content]);
1240
- return /*#__PURE__*/runtime.jsx(ErrorBoundary, {
1241
- content: content,
1242
- children: component
1243
- });
1244
- }
1245
-
1246
- var ToolCall = function (_a) {
1247
- var name = _a.name,
1248
- args = _a.args,
1249
- children = _a.children;
1250
- return /*#__PURE__*/runtime.jsxs("div", {
1251
- style: {
1252
- border: '1px solid #e0e0e0',
1253
- borderRadius: '4px',
1254
- margin: '8px 0',
1255
- backgroundColor: '#fafafa'
1256
- },
1257
- children: [/*#__PURE__*/runtime.jsxs("div", {
1258
- style: {
1259
- padding: '8px',
1260
- backgroundColor: '#f5f5f5',
1261
- borderBottom: '1px solid #e0e0e0',
1262
- fontWeight: 'bold',
1263
- display: 'flex',
1264
- alignItems: 'center'
1265
- },
1266
- children: [/*#__PURE__*/runtime.jsx("span", {
1267
- style: {
1268
- marginRight: '8px'
1269
- },
1270
- children: "\uD83D\uDD27"
1271
- }), /*#__PURE__*/runtime.jsxs("span", {
1272
- children: ["\u5DE5\u5177\u8C03\u7528: ", name]
1273
- })]
1274
- }), args && /*#__PURE__*/runtime.jsxs("div", {
1275
- style: {
1276
- padding: '8px'
1277
- },
1278
- children: [/*#__PURE__*/runtime.jsx("div", {
1279
- style: {
1280
- fontWeight: 'bold',
1281
- marginBottom: '4px'
1282
- },
1283
- children: "\u53C2\u6570:"
1284
- }), /*#__PURE__*/runtime.jsx("pre", {
1285
- style: {
1286
- backgroundColor: '#f0f0f0',
1287
- padding: '8px',
1288
- borderRadius: '4px',
1289
- overflowX: 'auto',
1290
- fontSize: '12px'
1291
- },
1292
- children: JSON.stringify(args, null, 2)
1293
- })]
1294
- }), children && /*#__PURE__*/runtime.jsxs("div", {
1295
- style: {
1296
- padding: '8px'
1297
- },
1298
- children: [/*#__PURE__*/runtime.jsx("div", {
1299
- style: {
1300
- fontWeight: 'bold',
1301
- marginBottom: '4px'
1302
- },
1303
- children: "\u7ED3\u679C:"
1304
- }), /*#__PURE__*/runtime.jsx("div", {
1305
- children: children
1306
- })]
1307
- })]
1308
- });
1309
- };
1310
-
1311
- // 导出 MDXStreamingParser 类
1312
-
1313
- exports.MDXStreamingParser = MDXStreamingParser;
1314
- exports.ReactAIRenderer = ReactAIRenderer;
1315
- exports.Think = Think;
1316
- exports.ToolCall = ToolCall;
1317
- exports.__awaiter = __awaiter;
1318
- exports.__generator = __generator;
1319
- exports.__read = __read;
1320
- //# sourceMappingURL=index-e07ca144.js.map