react-ai-renderer 0.1.1 → 0.1.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 (119) hide show
  1. package/dist/MermaidRenderer-07b34bcf.js +170 -0
  2. package/dist/{MermaidRenderer-cdeab8f8.js.map → MermaidRenderer-07b34bcf.js.map} +1 -1
  3. package/dist/MermaidRenderer-0aacea2f.js +170 -0
  4. package/dist/MermaidRenderer-0aacea2f.js.map +1 -0
  5. package/dist/MermaidRenderer-1c06834c.js +170 -0
  6. package/dist/MermaidRenderer-1c06834c.js.map +1 -0
  7. package/dist/MermaidRenderer-22b8cb81.js +170 -0
  8. package/dist/MermaidRenderer-22b8cb81.js.map +1 -0
  9. package/dist/MermaidRenderer-2438ceb1.js +170 -0
  10. package/dist/MermaidRenderer-2438ceb1.js.map +1 -0
  11. package/dist/MermaidRenderer-2f6d93a2.js +170 -0
  12. package/dist/MermaidRenderer-2f6d93a2.js.map +1 -0
  13. package/dist/MermaidRenderer-447e20f0.js +170 -0
  14. package/dist/MermaidRenderer-447e20f0.js.map +1 -0
  15. package/dist/MermaidRenderer-456abbe8.js +170 -0
  16. package/dist/MermaidRenderer-456abbe8.js.map +1 -0
  17. package/dist/MermaidRenderer-45a1e235.js +170 -0
  18. package/dist/MermaidRenderer-45a1e235.js.map +1 -0
  19. package/dist/MermaidRenderer-4b75a3e5.js +172 -0
  20. package/dist/{MermaidRenderer-1f4c47aa.js.map → MermaidRenderer-4b75a3e5.js.map} +1 -1
  21. package/dist/MermaidRenderer-59cd2aac.js +172 -0
  22. package/dist/MermaidRenderer-59cd2aac.js.map +1 -0
  23. package/dist/MermaidRenderer-61954263.js +172 -0
  24. package/dist/MermaidRenderer-61954263.js.map +1 -0
  25. package/dist/{MermaidRenderer-1f4c47aa.js → MermaidRenderer-62cbf217.js} +1 -1
  26. package/dist/MermaidRenderer-62cbf217.js.map +1 -0
  27. package/dist/MermaidRenderer-6323359c.js +170 -0
  28. package/dist/MermaidRenderer-6323359c.js.map +1 -0
  29. package/dist/{MermaidRenderer-cdeab8f8.js → MermaidRenderer-680adac3.js} +1 -1
  30. package/dist/MermaidRenderer-680adac3.js.map +1 -0
  31. package/dist/MermaidRenderer-771db0f2.js +172 -0
  32. package/dist/MermaidRenderer-771db0f2.js.map +1 -0
  33. package/dist/MermaidRenderer-7a5bd531.js +170 -0
  34. package/dist/MermaidRenderer-7a5bd531.js.map +1 -0
  35. package/dist/MermaidRenderer-94fceb26.js +172 -0
  36. package/dist/MermaidRenderer-94fceb26.js.map +1 -0
  37. package/dist/MermaidRenderer-a6a464ec.js +172 -0
  38. package/dist/MermaidRenderer-a6a464ec.js.map +1 -0
  39. package/dist/MermaidRenderer-a8c58389.js +172 -0
  40. package/dist/MermaidRenderer-a8c58389.js.map +1 -0
  41. package/dist/MermaidRenderer-b23c2eec.js +172 -0
  42. package/dist/MermaidRenderer-b23c2eec.js.map +1 -0
  43. package/dist/MermaidRenderer-b30dda58.js +170 -0
  44. package/dist/MermaidRenderer-b30dda58.js.map +1 -0
  45. package/dist/MermaidRenderer-b65fed60.js +172 -0
  46. package/dist/MermaidRenderer-b65fed60.js.map +1 -0
  47. package/dist/MermaidRenderer-c594187b.js +172 -0
  48. package/dist/MermaidRenderer-c594187b.js.map +1 -0
  49. package/dist/MermaidRenderer-c5f51ccf.js +172 -0
  50. package/dist/MermaidRenderer-c5f51ccf.js.map +1 -0
  51. package/dist/MermaidRenderer-cf69f9fc.js +172 -0
  52. package/dist/MermaidRenderer-cf69f9fc.js.map +1 -0
  53. package/dist/MermaidRenderer-fa15e3c7.js +172 -0
  54. package/dist/MermaidRenderer-fa15e3c7.js.map +1 -0
  55. package/dist/MermaidRenderer-fc75606f.js +170 -0
  56. package/dist/MermaidRenderer-fc75606f.js.map +1 -0
  57. package/dist/index-27d5e758.js +1399 -0
  58. package/dist/index-27d5e758.js.map +1 -0
  59. package/dist/index-2b2eb026.js +1393 -0
  60. package/dist/index-2b2eb026.js.map +1 -0
  61. package/dist/index-34e4d478.js +1289 -0
  62. package/dist/index-34e4d478.js.map +1 -0
  63. package/dist/index-4881fdf3.js +1458 -0
  64. package/dist/index-4881fdf3.js.map +1 -0
  65. package/dist/index-4d8e81d1.js +1264 -0
  66. package/dist/index-4d8e81d1.js.map +1 -0
  67. package/dist/{index-c0f5a1e9.js → index-4f25eb16.js} +262 -215
  68. package/dist/index-4f25eb16.js.map +1 -0
  69. package/dist/index-53d781f0.js +1476 -0
  70. package/dist/index-53d781f0.js.map +1 -0
  71. package/dist/index-543584d8.js +1398 -0
  72. package/dist/index-543584d8.js.map +1 -0
  73. package/dist/index-54c78282.js +1474 -0
  74. package/dist/index-54c78282.js.map +1 -0
  75. package/dist/index-57a0454a.js +1441 -0
  76. package/dist/index-57a0454a.js.map +1 -0
  77. package/dist/index-58ab9759.js +1424 -0
  78. package/dist/index-58ab9759.js.map +1 -0
  79. package/dist/index-58ee3084.js +1399 -0
  80. package/dist/index-58ee3084.js.map +1 -0
  81. package/dist/index-5edd5559.js +1289 -0
  82. package/dist/index-5edd5559.js.map +1 -0
  83. package/dist/index-65168e57.js +1263 -0
  84. package/dist/index-65168e57.js.map +1 -0
  85. package/dist/index-66021d90.js +1431 -0
  86. package/dist/index-66021d90.js.map +1 -0
  87. package/dist/index-71e57dce.js +1425 -0
  88. package/dist/index-71e57dce.js.map +1 -0
  89. package/dist/index-742d8be6.js +1290 -0
  90. package/dist/index-742d8be6.js.map +1 -0
  91. package/dist/index-813be4d3.js +1425 -0
  92. package/dist/index-813be4d3.js.map +1 -0
  93. package/dist/index-82c906b1.js +1448 -0
  94. package/dist/index-82c906b1.js.map +1 -0
  95. package/dist/index-a7fb8ff9.js +1432 -0
  96. package/dist/index-a7fb8ff9.js.map +1 -0
  97. package/dist/{index-1e589dfb.js → index-b4765fbd.js} +262 -216
  98. package/dist/index-b4765fbd.js.map +1 -0
  99. package/dist/index-b78ff7b5.js +1399 -0
  100. package/dist/index-b78ff7b5.js.map +1 -0
  101. package/dist/index-c56180b9.js +1425 -0
  102. package/dist/index-c56180b9.js.map +1 -0
  103. package/dist/index-d5855b9f.js +1367 -0
  104. package/dist/index-d5855b9f.js.map +1 -0
  105. package/dist/index-d63be97b.js +1263 -0
  106. package/dist/index-d63be97b.js.map +1 -0
  107. package/dist/index-dd9fe728.js +1457 -0
  108. package/dist/index-dd9fe728.js.map +1 -0
  109. package/dist/index-e0ce1691.js +1467 -0
  110. package/dist/index-e0ce1691.js.map +1 -0
  111. package/dist/index-fadb7b0b.js +1450 -0
  112. package/dist/index-fadb7b0b.js.map +1 -0
  113. package/dist/index.d.ts +54 -13
  114. package/dist/index.es.js +1 -1
  115. package/dist/index.js +2 -1
  116. package/dist/index.js.map +1 -1
  117. package/package.json +1 -1
  118. package/dist/index-1e589dfb.js.map +0 -1
  119. package/dist/index-c0f5a1e9.js.map +0 -1
@@ -29,168 +29,17 @@ function _interopNamespaceDefault(e) {
29
29
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
30
30
  var runtime__namespace = /*#__PURE__*/_interopNamespaceDefault(runtime);
31
31
 
32
- /******************************************************************************
33
- Copyright (c) Microsoft Corporation.
34
-
35
- Permission to use, copy, modify, and/or distribute this software for any
36
- purpose with or without fee is hereby granted.
37
-
38
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
39
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
40
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
41
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
42
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
43
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
44
- PERFORMANCE OF THIS SOFTWARE.
45
- ***************************************************************************** */
46
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
47
-
48
- var extendStatics = function(d, b) {
49
- extendStatics = Object.setPrototypeOf ||
50
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
51
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
52
- return extendStatics(d, b);
53
- };
54
-
55
- function __extends(d, b) {
56
- if (typeof b !== "function" && b !== null)
57
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
58
- extendStatics(d, b);
59
- function __() { this.constructor = d; }
60
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
61
- }
62
-
63
- var __assign = function() {
64
- __assign = Object.assign || function __assign(t) {
65
- for (var s, i = 1, n = arguments.length; i < n; i++) {
66
- s = arguments[i];
67
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
68
- }
69
- return t;
70
- };
71
- return __assign.apply(this, arguments);
72
- };
73
-
74
- function __rest(s, e) {
75
- var t = {};
76
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
77
- t[p] = s[p];
78
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
79
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
80
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
81
- t[p[i]] = s[p[i]];
82
- }
83
- return t;
84
- }
85
-
86
- function __awaiter(thisArg, _arguments, P, generator) {
87
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
88
- return new (P || (P = Promise))(function (resolve, reject) {
89
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
90
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
91
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
92
- step((generator = generator.apply(thisArg, _arguments || [])).next());
93
- });
94
- }
95
-
96
- function __generator(thisArg, body) {
97
- 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);
98
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
99
- function verb(n) { return function (v) { return step([n, v]); }; }
100
- function step(op) {
101
- if (f) throw new TypeError("Generator is already executing.");
102
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
103
- 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;
104
- if (y = 0, t) op = [op[0] & 2, t.value];
105
- switch (op[0]) {
106
- case 0: case 1: t = op; break;
107
- case 4: _.label++; return { value: op[1], done: false };
108
- case 5: _.label++; y = op[1]; op = [0]; continue;
109
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
110
- default:
111
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
112
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
113
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
114
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
115
- if (t[2]) _.ops.pop();
116
- _.trys.pop(); continue;
117
- }
118
- op = body.call(thisArg, _);
119
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
120
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
121
- }
122
- }
123
-
124
- function __values(o) {
125
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
126
- if (m) return m.call(o);
127
- if (o && typeof o.length === "number") return {
128
- next: function () {
129
- if (o && i >= o.length) o = void 0;
130
- return { value: o && o[i++], done: !o };
131
- }
132
- };
133
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
134
- }
135
-
136
- function __read(o, n) {
137
- var m = typeof Symbol === "function" && o[Symbol.iterator];
138
- if (!m) return o;
139
- var i = m.call(o), r, ar = [], e;
140
- try {
141
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
142
- }
143
- catch (error) { e = { error: error }; }
144
- finally {
145
- try {
146
- if (r && !r.done && (m = i["return"])) m.call(i);
147
- }
148
- finally { if (e) throw e.error; }
149
- }
150
- return ar;
151
- }
152
-
153
- function __spreadArray(to, from, pack) {
154
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
155
- if (ar || !(i in from)) {
156
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
157
- ar[i] = from[i];
158
- }
159
- }
160
- return to.concat(ar || Array.prototype.slice.call(from));
161
- }
162
-
163
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
164
- var e = new Error(message);
165
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
166
- };
167
-
168
32
  var MDXStreamingParser = /** @class */function () {
169
33
  function MDXStreamingParser(components) {
170
- this.registeredComponents = new Set(components);
34
+ // 将组件名称存储在Set中,而不是整个组件对象
35
+ this.registeredComponents = new Set(components.map(function (c) {
36
+ return c.name;
37
+ }));
171
38
  this.messages = new Map();
172
39
  }
173
- MDXStreamingParser.prototype.findComponentByName = function (name) {
174
- var e_1, _a;
175
- try {
176
- for (var _b = __values(this.registeredComponents), _c = _b.next(); !_c.done; _c = _b.next()) {
177
- var component = _c.value;
178
- if (component.name === name) {
179
- return component;
180
- }
181
- }
182
- } catch (e_1_1) {
183
- e_1 = {
184
- error: e_1_1
185
- };
186
- } finally {
187
- try {
188
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
189
- } finally {
190
- if (e_1) throw e_1.error;
191
- }
192
- }
193
- return undefined; // Return undefined if no component is found
40
+ // 检查组件是否已注册
41
+ MDXStreamingParser.prototype.isComponentRegistered = function (name) {
42
+ return this.registeredComponents.has(name);
194
43
  };
195
44
  MDXStreamingParser.prototype.parse = function (messageId, input) {
196
45
  var state = {
@@ -211,9 +60,10 @@ var MDXStreamingParser = /** @class */function () {
211
60
  break;
212
61
  }
213
62
  var tagName = input.slice(i + 2, closeTagEnd);
214
- var registerComponentInfo = this.findComponentByName(tagName);
63
+ // 检查组件是否已注册
64
+ var isRegistered = this.isComponentRegistered(tagName);
215
65
  // 如果组件未注册,则作为文本处理
216
- if (!registerComponentInfo) {
66
+ if (!isRegistered) {
217
67
  state.buffer += input.slice(i, closeTagEnd + 1);
218
68
  i = closeTagEnd + 1;
219
69
  continue;
@@ -248,9 +98,10 @@ var MDXStreamingParser = /** @class */function () {
248
98
  if (tagMatch) {
249
99
  // Handle accumulated text before the tag
250
100
  var componentName = tagMatch[1];
251
- var registerComponentInfo = this.findComponentByName(componentName);
101
+ // 检查组件是否已注册
102
+ var isRegistered = this.isComponentRegistered(componentName);
252
103
  // 如果组件未注册,将整个标签作为文本处理
253
- if (!registerComponentInfo) {
104
+ if (!isRegistered) {
254
105
  state.buffer += input[i];
255
106
  i++;
256
107
  continue;
@@ -278,20 +129,16 @@ var MDXStreamingParser = /** @class */function () {
278
129
  });
279
130
  }
280
131
  state.buffer = '';
281
- // const componentName = tagMatch[1];
282
- var selfClosing = false;
283
- // const registerComponentInfo = this.findComponentByName(componentName);
284
- if (registerComponentInfo) {
285
- selfClosing = registerComponentInfo.selfClosing;
286
- }
287
- var _a = this.parseComponentTag(input.slice(i), selfClosing),
132
+ // 动态解析标签形式,不再依赖预先注册的 selfClosing 属性
133
+ var _a = this.parseComponentTag(input.slice(i)),
288
134
  props = _a.props,
289
- endIndex = _a.endIndex;
135
+ endIndex = _a.endIndex,
136
+ selfClosing = _a.selfClosing;
290
137
  var component = {
291
138
  type: "component",
292
139
  value: componentName,
293
140
  props: props,
294
- selfClosing: selfClosing
141
+ selfClosing: selfClosing // 使用实际解析出的标签形式
295
142
  };
296
143
  if (!selfClosing) {
297
144
  state.stack.push(component);
@@ -382,22 +229,21 @@ var MDXStreamingParser = /** @class */function () {
382
229
  }
383
230
  return input.length;
384
231
  };
385
- MDXStreamingParser.prototype.parseComponentTag = function (input, selfClosing) {
232
+ MDXStreamingParser.prototype.parseComponentTag = function (input) {
386
233
  var props = {};
387
234
  var i = 0;
388
235
  // 跳过组件名
389
236
  while (i < input.length && input[i] !== ' ' && input[i] !== '>') i++;
390
- if (!selfClosing) {
391
- return this.parsePropsCommon(input);
392
- }
393
- // 使用 parseProps 方法解析属性
394
- var propsContent = input.slice(i);
395
- var parsedProps = this.parsePropsSelfClosing(propsContent);
237
+ // 使用 parsePropsCommon 方法解析属性,该方法会返回标签形式信息
238
+ var _a = this.parsePropsCommon(input),
239
+ parsedProps = _a.props,
240
+ endIndex = _a.endIndex,
241
+ selfClosing = _a.selfClosing;
396
242
  Object.assign(props, parsedProps);
397
- var endIndex = this.findComponentClose(input, i);
398
243
  return {
399
244
  props: props,
400
- endIndex: endIndex
245
+ endIndex: endIndex,
246
+ selfClosing: selfClosing
401
247
  };
402
248
  };
403
249
  MDXStreamingParser.prototype.parsePropsCommon = function (input) {
@@ -537,6 +383,130 @@ var MDXStreamingParser = /** @class */function () {
537
383
  return MDXStreamingParser;
538
384
  }();
539
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 __read(o, n) {
479
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
480
+ if (!m) return o;
481
+ var i = m.call(o), r, ar = [], e;
482
+ try {
483
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
484
+ }
485
+ catch (error) { e = { error: error }; }
486
+ finally {
487
+ try {
488
+ if (r && !r.done && (m = i["return"])) m.call(i);
489
+ }
490
+ finally { if (e) throw e.error; }
491
+ }
492
+ return ar;
493
+ }
494
+
495
+ function __spreadArray(to, from, pack) {
496
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
497
+ if (ar || !(i in from)) {
498
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
499
+ ar[i] = from[i];
500
+ }
501
+ }
502
+ return to.concat(ar || Array.prototype.slice.call(from));
503
+ }
504
+
505
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
506
+ var e = new Error(message);
507
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
508
+ };
509
+
540
510
  var CodeHighlight = function (_a) {
541
511
  var textContent = _a.textContent,
542
512
  _b = _a.language,
@@ -587,7 +557,7 @@ var CodeHighlight = function (_a) {
587
557
  if (language === "mermaid") {
588
558
  // 动态导入 MermaidRenderer 组件
589
559
  var MermaidRenderer = /*#__PURE__*/React.lazy(function () {
590
- return Promise.resolve().then(function () { return require('./MermaidRenderer-1f4c47aa.js'); }).catch(function () {
560
+ return Promise.resolve().then(function () { return require('./MermaidRenderer-b65fed60.js'); }).catch(function () {
591
561
  return {
592
562
  default: function () {
593
563
  return /*#__PURE__*/runtime.jsx("div", {});
@@ -790,10 +760,35 @@ var AComponent = function (aProps) {
790
760
  var href = aProps.href || "";
791
761
  var isInternal = /^\/#/i.test(href);
792
762
  var target = isInternal ? "_self" : (_a = aProps.target) !== null && _a !== void 0 ? _a : "_blank";
763
+ // 增强链接样式,使其更加明显
764
+ var linkStyle = {
765
+ color: '#1a73e8',
766
+ fontWeight: '600',
767
+ borderBottom: '2px solid #1a73e8',
768
+ paddingBottom: '2px',
769
+ transition: 'all 0.2s ease'
770
+ };
771
+ // 鼠标悬停效果
772
+ var hoverStyle = {
773
+ color: '#0d47a1',
774
+ borderBottom: '2px solid #0d47a1',
775
+ backgroundColor: 'rgba(26, 115, 232, 0.1)'
776
+ };
777
+ // 合并原有属性和新样式
793
778
  return /*#__PURE__*/runtime.jsx("a", {
794
- color: "red",
795
779
  ...aProps,
796
- target: target
780
+ target: target,
781
+ style: __assign(__assign({}, linkStyle), aProps.style),
782
+ onMouseEnter: function (e) {
783
+ var target = e.target;
784
+ Object.assign(target.style, hoverStyle);
785
+ aProps.onMouseEnter && aProps.onMouseEnter(e);
786
+ },
787
+ onMouseLeave: function (e) {
788
+ var target = e.target;
789
+ Object.assign(target.style, linkStyle);
790
+ aProps.onMouseLeave && aProps.onMouseLeave(e);
791
+ }
797
792
  });
798
793
  };
799
794
  // Pre 组件
@@ -896,6 +891,15 @@ function remarkThinkUpdate(content) {
896
891
  resultContent: resultContent
897
892
  };
898
893
  }
894
+ /**
895
+ * 转义流式内容中的特殊字符,防止MDX解析错误
896
+ * @param content 需要转义的内容
897
+ * @returns 转义后的内容
898
+ */
899
+ function escapeContentForStream(content) {
900
+ if (typeof content !== 'string') return content;
901
+ return content.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/{/g, '&#123;').replace(/}/g, '&#125;');
902
+ }
899
903
 
900
904
  var renderTimer = null;
901
905
  // 辅助函数:格式化props
@@ -917,7 +921,7 @@ function formatProps(props) {
917
921
  }
918
922
  function renderMdx(mdxContent, scope, registeredComponents) {
919
923
  return __awaiter(this, void 0, void 0, function () {
920
- var componentTagRegex, usedComponents, match, vf, XComponent, e_1;
924
+ var componentTagRegex, usedComponents, match, vf, XComponent;
921
925
  return __generator(this, function (_a) {
922
926
  switch (_a.label) {
923
927
  case 0:
@@ -952,19 +956,16 @@ function renderMdx(mdxContent, scope, registeredComponents) {
952
956
  scope: scope
953
957
  })];
954
958
  case 3:
955
- e_1 = _a.sent();
959
+ _a.sent();
956
960
  return [2 /*return*/, new Promise(function (resolve) {
957
961
  renderTimer = setTimeout(function () {
958
- console.log(mdxContent, 'mdxContent');
959
- console.log(e_1, 'error');
960
962
  resolve(/*#__PURE__*/React__namespace.createElement('div', {
961
963
  style: {
962
- fontSize: '14px',
963
964
  backgroundColor: 'transparent'
964
965
  }
965
966
  }, mdxContent));
966
967
  clearTimeout(renderTimer); // 清理定时器
967
- }, 1000); // 1秒延迟
968
+ }, 2000); // 1秒延迟
968
969
  })];
969
970
  case 4:
970
971
  return [2 /*return*/];
@@ -975,48 +976,81 @@ function renderMdx(mdxContent, scope, registeredComponents) {
975
976
  // 递归解析组件的函数
976
977
  function parseComponentRecursively(allComponentHandlers, item, scope) {
977
978
  return __awaiter(this, void 0, void 0, function () {
978
- var componentHandler, props, propsString, childrenContent_1, parsedChildren_1, componentString;
979
+ var componentHandler, componentString_1, parsedChildren, props, propsString, childrenContent_1, parsedChildren_1, componentString;
979
980
  return __generator(this, function (_a) {
980
981
  switch (_a.label) {
981
982
  case 0:
982
983
  if (item.type === 'text') {
983
984
  return [2 /*return*/, item.value];
984
985
  }
985
- if (!(item.type === 'component')) return [3 /*break*/, 3];
986
+ if (!(item.type === 'component')) return [3 /*break*/, 8];
986
987
  componentHandler = allComponentHandlers.find(function (c) {
987
988
  return c.name === item.value;
988
989
  });
989
- if (!componentHandler) {
990
- return [2 /*return*/, null];
990
+ if (!!componentHandler) return [3 /*break*/, 5];
991
+ componentString_1 = "<".concat(item.value);
992
+ if (item.props) {
993
+ componentString_1 += ' ' + Object.entries(item.props).map(function (_a) {
994
+ var _b = __read(_a, 2),
995
+ key = _b[0],
996
+ value = _b[1];
997
+ if (typeof value === 'string') {
998
+ return "".concat(key, "=\"").concat(value, "\"");
999
+ }
1000
+ try {
1001
+ return "".concat(key, "={").concat(JSON.stringify(value), "}");
1002
+ } catch (e) {
1003
+ return "".concat(key, "=\"[object Object]\"");
1004
+ }
1005
+ }).join(' ');
991
1006
  }
1007
+ if (!item.selfClosing) return [3 /*break*/, 1];
1008
+ componentString_1 += ' />';
1009
+ return [3 /*break*/, 4];
1010
+ case 1:
1011
+ componentString_1 += '>';
1012
+ if (!(item.children && Array.isArray(item.children))) return [3 /*break*/, 3];
1013
+ return [4 /*yield*/, Promise.all(item.children.map(function (child) {
1014
+ return parseComponentRecursively(allComponentHandlers, child, scope);
1015
+ }))];
1016
+ case 2:
1017
+ parsedChildren = _a.sent();
1018
+ componentString_1 += parsedChildren.join('');
1019
+ _a.label = 3;
1020
+ case 3:
1021
+ componentString_1 += "</".concat(item.value, ">");
1022
+ _a.label = 4;
1023
+ case 4:
1024
+ return [2 /*return*/, componentString_1];
1025
+ case 5:
992
1026
  props = __assign(__assign({}, item.props), {
993
1027
  key: generateRandomName()
994
1028
  });
995
1029
  propsString = formatProps(props);
996
1030
  propsString += " scope={props.scope}";
997
1031
  childrenContent_1 = '';
998
- if (!(item.children && Array.isArray(item.children))) return [3 /*break*/, 2];
1032
+ if (!(item.children && Array.isArray(item.children))) return [3 /*break*/, 7];
999
1033
  return [4 /*yield*/, Promise.all(item.children.map(function (child) {
1000
1034
  return parseComponentRecursively(allComponentHandlers, child, scope);
1001
1035
  }))];
1002
- case 1:
1036
+ case 6:
1003
1037
  parsedChildren_1 = _a.sent();
1004
1038
  item.children.map(function (item, index) {
1005
1039
  if (item.type === 'text') {
1006
- childrenContent_1 += parsedChildren_1[index]; // encodeURIComponent(parsedChildren[index]);
1040
+ childrenContent_1 += escapeContentForStream(parsedChildren_1[index]); // encodeURIComponent(parsedChildren[index]);
1007
1041
  } else {
1008
1042
  childrenContent_1 += parsedChildren_1[index];
1009
1043
  }
1010
1044
  });
1011
- _a.label = 2;
1012
- case 2:
1045
+ _a.label = 7;
1046
+ case 7:
1013
1047
  // 调用组件的渲染钩子
1014
1048
  if (componentHandler.onRender) {
1015
1049
  componentHandler.onRender(item, scope);
1016
1050
  }
1017
1051
  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");
1018
1052
  return [2 /*return*/, componentString];
1019
- case 3:
1053
+ case 8:
1020
1054
  return [2 /*return*/, null];
1021
1055
  }
1022
1056
  });
@@ -1088,11 +1122,12 @@ function ReactAIRenderer(_a) {
1088
1122
  var content = _a.content,
1089
1123
  _b = _a.scope,
1090
1124
  scope = _b === void 0 ? {} : _b,
1091
- components = _a.components,
1125
+ _c = _a.components,
1126
+ components = _c === void 0 ? {} : _c,
1092
1127
  children = _a.children,
1093
- _c = _a.componentHandlers,
1094
- componentHandlers = _c === void 0 ? [] : _c;
1095
- content = content || children;
1128
+ _d = _a.componentHandlers,
1129
+ componentHandlers = _d === void 0 ? [] : _d;
1130
+ content = content || children || '';
1096
1131
  var allComponents = __assign(__assign({}, BuiltInComponents), components);
1097
1132
  // 修复:确保 components 是一个对象后再使用 Object.entries
1098
1133
  var allComponentHandlers = __spreadArray(__spreadArray([], __read(components ? Object.entries(components).filter(function (_a) {
@@ -1105,7 +1140,6 @@ function ReactAIRenderer(_a) {
1105
1140
  var _b = __read(_a, 2),
1106
1141
  name = _b[0],
1107
1142
  component = _b[1];
1108
- console.log(name, 'name');
1109
1143
  var selfClosing = isSelfClosingComponent(component);
1110
1144
  return {
1111
1145
  component: component,
@@ -1113,15 +1147,15 @@ function ReactAIRenderer(_a) {
1113
1147
  selfClosing: selfClosing
1114
1148
  };
1115
1149
  }) : []), false), __read(componentHandlers), false);
1116
- var _d = __read(React.useState(null), 2),
1117
- component = _d[0],
1118
- setComponent = _d[1];
1150
+ var _e = __read(React.useState(null), 2),
1151
+ component = _e[0],
1152
+ setComponent = _e[1];
1119
1153
  var parser = new MDXStreamingParser(allComponentHandlers);
1120
- var mdxContent = content;
1154
+ var mdxContent = content || '';
1121
1155
  React.useEffect(function () {
1122
1156
  var parseMDX = function () {
1123
1157
  return __awaiter(_this, void 0, void 0, function () {
1124
- var ThinkComponent, ResultComponent, _a, thinkContent, resultContent, parsedData, parsedComponents, finalComponent, MDXComponent;
1158
+ var ThinkComponent, ResultComponent, _a, thinkContent, resultContent, parsedData, parsedComponents, finalComponent, i, _result, MDXComponent;
1125
1159
  return __generator(this, function (_b) {
1126
1160
  switch (_b.label) {
1127
1161
  case 0:
@@ -1134,7 +1168,7 @@ function ReactAIRenderer(_a) {
1134
1168
  ThinkComponent = _b.sent();
1135
1169
  _b.label = 2;
1136
1170
  case 2:
1137
- if (!resultContent) return [3 /*break*/, 5];
1171
+ if (!resultContent) return [3 /*break*/, 8];
1138
1172
  resultContent = fixMDXContent(resultContent);
1139
1173
  parsedData = parser.parse('magic', resultContent);
1140
1174
  return [4 /*yield*/, Promise.all(parsedData.map(function (item) {
@@ -1142,14 +1176,25 @@ function ReactAIRenderer(_a) {
1142
1176
  }))];
1143
1177
  case 3:
1144
1178
  parsedComponents = _b.sent();
1145
- return [4 /*yield*/, renderMdx(parsedComponents.join('\n'), scope, allComponents)];
1179
+ finalComponent = [];
1180
+ i = 0;
1181
+ _b.label = 4;
1146
1182
  case 4:
1147
- finalComponent = _b.sent();
1183
+ if (!(i < parsedComponents.length)) return [3 /*break*/, 7];
1184
+ return [4 /*yield*/, renderMdx(parsedComponents[i], scope, allComponents)];
1185
+ case 5:
1186
+ _result = _b.sent();
1187
+ finalComponent.push(_result);
1188
+ _b.label = 6;
1189
+ case 6:
1190
+ i++;
1191
+ return [3 /*break*/, 4];
1192
+ case 7:
1148
1193
  ResultComponent = /*#__PURE__*/runtime.jsx("div", {
1149
1194
  children: finalComponent
1150
1195
  });
1151
- _b.label = 5;
1152
- case 5:
1196
+ _b.label = 8;
1197
+ case 8:
1153
1198
  MDXComponent = /*#__PURE__*/runtime.jsxs(React.Fragment, {
1154
1199
  children: [ThinkComponent, ResultComponent]
1155
1200
  });
@@ -1232,11 +1277,13 @@ var ToolCall = function (_a) {
1232
1277
  });
1233
1278
  };
1234
1279
 
1235
- // 默认导出
1280
+ // 导出 MDXStreamingParser 类
1236
1281
 
1282
+ exports.MDXStreamingParser = MDXStreamingParser;
1237
1283
  exports.ReactAIRenderer = ReactAIRenderer;
1238
1284
  exports.Think = Think;
1239
1285
  exports.ToolCall = ToolCall;
1240
1286
  exports.__awaiter = __awaiter;
1241
1287
  exports.__generator = __generator;
1242
1288
  exports.__read = __read;
1289
+ //# sourceMappingURL=index-4f25eb16.js.map