@ant-design/agentic-ui 2.21.0 → 2.23.0

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 (32) hide show
  1. package/dist/Bubble/BubbleBeforeNode.js +9 -9
  2. package/dist/MarkdownEditor/editor/Editor.js +14 -3
  3. package/dist/MarkdownEditor/editor/elements/TagPopup/index.js +4 -4
  4. package/dist/MarkdownEditor/editor/elements/TagPopup/style.js +14 -12
  5. package/dist/MarkdownEditor/editor/parser/parse/applyContextPropsAndConfig.d.ts +8 -0
  6. package/dist/MarkdownEditor/editor/parser/parse/applyContextPropsAndConfig.js +58 -0
  7. package/dist/MarkdownEditor/editor/parser/parse/parseBlockElements.d.ts +67 -0
  8. package/dist/MarkdownEditor/editor/parser/parse/parseBlockElements.js +289 -0
  9. package/dist/MarkdownEditor/editor/parser/parse/parseCode.d.ts +2 -1
  10. package/dist/MarkdownEditor/editor/parser/parse/parseCode.js +15 -8
  11. package/dist/MarkdownEditor/editor/parser/parse/parseElements.d.ts +27 -0
  12. package/dist/MarkdownEditor/editor/parser/parse/parseElements.js +83 -0
  13. package/dist/MarkdownEditor/editor/parser/parse/parseEmptyLines.d.ts +9 -0
  14. package/dist/MarkdownEditor/editor/parser/parse/parseEmptyLines.js +60 -0
  15. package/dist/MarkdownEditor/editor/parser/parse/parseFootnote.d.ts +10 -0
  16. package/dist/MarkdownEditor/editor/parser/parse/parseFootnote.js +12 -0
  17. package/dist/MarkdownEditor/editor/parser/parse/parseHtml.d.ts +63 -0
  18. package/dist/MarkdownEditor/editor/parser/parse/parseHtml.js +781 -0
  19. package/dist/MarkdownEditor/editor/parser/parse/parseMath.d.ts +24 -0
  20. package/dist/MarkdownEditor/editor/parser/parse/parseMath.js +58 -0
  21. package/dist/MarkdownEditor/editor/parser/parse/parseMedia.d.ts +27 -0
  22. package/dist/MarkdownEditor/editor/parser/parse/parseMedia.js +127 -0
  23. package/dist/MarkdownEditor/editor/parser/parse/parseTable.js +36 -3
  24. package/dist/MarkdownEditor/editor/parser/parse/parseText.d.ts +26 -0
  25. package/dist/MarkdownEditor/editor/parser/parse/parseText.js +304 -0
  26. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.d.ts +3 -40
  27. package/dist/MarkdownEditor/editor/parser/parserMarkdownToSlateNode.js +189 -1856
  28. package/dist/MarkdownEditor/editor/parser/parserSlateNodeToMarkdown.js +131 -18
  29. package/dist/MarkdownEditor/editor/parser/remarkParse.js +24 -17
  30. package/dist/MarkdownEditor/editor/plugins/elements.js +1 -1
  31. package/dist/Plugins/code/components/CodeToolbar.js +3 -16
  32. package/package.json +1 -1
@@ -0,0 +1,781 @@
1
+ function _array_like_to_array(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _array_with_holes(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _array_without_holes(arr) {
10
+ if (Array.isArray(arr)) return _array_like_to_array(arr);
11
+ }
12
+ function _define_property(obj, key, value) {
13
+ if (key in obj) {
14
+ Object.defineProperty(obj, key, {
15
+ value: value,
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true
19
+ });
20
+ } else {
21
+ obj[key] = value;
22
+ }
23
+ return obj;
24
+ }
25
+ function _iterable_to_array(iter) {
26
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
27
+ }
28
+ function _iterable_to_array_limit(arr, i) {
29
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
30
+ if (_i == null) return;
31
+ var _arr = [];
32
+ var _n = true;
33
+ var _d = false;
34
+ var _s, _e;
35
+ try {
36
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
37
+ _arr.push(_s.value);
38
+ if (i && _arr.length === i) break;
39
+ }
40
+ } catch (err) {
41
+ _d = true;
42
+ _e = err;
43
+ } finally{
44
+ try {
45
+ if (!_n && _i["return"] != null) _i["return"]();
46
+ } finally{
47
+ if (_d) throw _e;
48
+ }
49
+ }
50
+ return _arr;
51
+ }
52
+ function _non_iterable_rest() {
53
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
54
+ }
55
+ function _non_iterable_spread() {
56
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
57
+ }
58
+ function _object_spread(target) {
59
+ for(var i = 1; i < arguments.length; i++){
60
+ var source = arguments[i] != null ? arguments[i] : {};
61
+ var ownKeys = Object.keys(source);
62
+ if (typeof Object.getOwnPropertySymbols === "function") {
63
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
64
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
65
+ }));
66
+ }
67
+ ownKeys.forEach(function(key) {
68
+ _define_property(target, key, source[key]);
69
+ });
70
+ }
71
+ return target;
72
+ }
73
+ function ownKeys(object, enumerableOnly) {
74
+ var keys = Object.keys(object);
75
+ if (Object.getOwnPropertySymbols) {
76
+ var symbols = Object.getOwnPropertySymbols(object);
77
+ if (enumerableOnly) {
78
+ symbols = symbols.filter(function(sym) {
79
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
80
+ });
81
+ }
82
+ keys.push.apply(keys, symbols);
83
+ }
84
+ return keys;
85
+ }
86
+ function _object_spread_props(target, source) {
87
+ source = source != null ? source : {};
88
+ if (Object.getOwnPropertyDescriptors) {
89
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
90
+ } else {
91
+ ownKeys(Object(source)).forEach(function(key) {
92
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
93
+ });
94
+ }
95
+ return target;
96
+ }
97
+ function _sliced_to_array(arr, i) {
98
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
99
+ }
100
+ function _to_consumable_array(arr) {
101
+ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
102
+ }
103
+ function _type_of(obj) {
104
+ "@swc/helpers - typeof";
105
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
106
+ }
107
+ function _unsupported_iterable_to_array(o, minLen) {
108
+ if (!o) return;
109
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
110
+ var n = Object.prototype.toString.call(o).slice(8, -1);
111
+ if (n === "Object" && o.constructor) n = o.constructor.name;
112
+ if (n === "Map" || n === "Set") return Array.from(n);
113
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
114
+ }
115
+ import json5 from "json5";
116
+ import { htmlToFragmentList } from "../../plugins/insertParsedHtmlNodes";
117
+ import { EditorUtils } from "../../utils";
118
+ import partialJsonParse from "../json-parse";
119
+ /**
120
+ * 解码 URI 组件,处理错误情况
121
+ */ export var decodeURIComponentUrl = function(url) {
122
+ try {
123
+ return decodeURIComponent(url);
124
+ } catch (e) {
125
+ console.error('Failed to decode URI component:', e);
126
+ return url;
127
+ }
128
+ };
129
+ /**
130
+ * 检测和解析 think 标签
131
+ * @param str - 要检测的字符串
132
+ * @returns think 标签的内容,如果不是 think 标签则返回 null
133
+ */ var findThinkElement = function(str) {
134
+ try {
135
+ // 匹配 <think>内容</think> 格式
136
+ var thinkMatch = str.match(/^\s*<think>([\s\S]*?)<\/think>\s*$/);
137
+ if (thinkMatch) {
138
+ return {
139
+ content: thinkMatch[1].trim()
140
+ };
141
+ }
142
+ return null;
143
+ } catch (e) {
144
+ return null;
145
+ }
146
+ };
147
+ /**
148
+ * 检测和解析 answer 标签
149
+ * @param str - 要检测的字符串
150
+ * @returns answer 标签的内容,如果不是 answer 标签则返回 null
151
+ */ var findAnswerElement = function(str) {
152
+ try {
153
+ // 匹配 <answer>内容</answer> 格式
154
+ var answerMatch = str.match(/^\s*<answer>([\s\S]*?)<\/answer>\s*$/);
155
+ if (answerMatch) {
156
+ return {
157
+ content: answerMatch[1].trim()
158
+ };
159
+ }
160
+ return null;
161
+ } catch (e) {
162
+ return null;
163
+ }
164
+ };
165
+ /**
166
+ * 从 HTML 字符串中提取媒体元素属性
167
+ */ var extractMediaAttributes = function(str) {
168
+ var _str_match, _str_match1, _str_match2, _str_match3, _str_match4;
169
+ return {
170
+ height: (_str_match = str.match(/height="(\d+)"/)) === null || _str_match === void 0 ? void 0 : _str_match[1],
171
+ width: (_str_match1 = str.match(/width="(\d+)"/)) === null || _str_match1 === void 0 ? void 0 : _str_match1[1],
172
+ align: (_str_match2 = str.match(/data-align="(\w+)"/)) === null || _str_match2 === void 0 ? void 0 : _str_match2[1],
173
+ alt: (_str_match3 = str.match(/alt="([^"\n]+)"/)) === null || _str_match3 === void 0 ? void 0 : _str_match3[1],
174
+ controls: str.match(/controls/),
175
+ autoplay: str.match(/autoplay/),
176
+ loop: str.match(/loop/),
177
+ muted: str.match(/muted/),
178
+ poster: (_str_match4 = str.match(/poster="([^"\n]+)"/)) === null || _str_match4 === void 0 ? void 0 : _str_match4[1]
179
+ };
180
+ };
181
+ /**
182
+ * 构建媒体元素对象
183
+ */ var buildMediaElement = function(url, tagName, attrs) {
184
+ var result = {
185
+ url: url,
186
+ align: attrs.align,
187
+ alt: attrs.alt,
188
+ tagName: tagName,
189
+ controls: !!attrs.controls,
190
+ autoplay: !!attrs.autoplay,
191
+ loop: !!attrs.loop,
192
+ muted: !!attrs.muted,
193
+ poster: attrs.poster
194
+ };
195
+ // 只有当值存在时才设置,避免类型错误
196
+ if (attrs.height) {
197
+ result.height = +attrs.height;
198
+ }
199
+ if (attrs.width) {
200
+ result.width = +attrs.width;
201
+ }
202
+ return result;
203
+ };
204
+ /**
205
+ * 从字符串中提取视频源 URL
206
+ */ var extractVideoSource = function(str, tagName) {
207
+ // 首先尝试从标签本身获取 src 属性
208
+ var url = str.match(/src="([^"\n]+)"/);
209
+ // 如果是 video 标签且没有找到 src,尝试从 source 标签中获取
210
+ if (tagName === 'video' && !url) {
211
+ var sourceMatch = str.match(/<source[^>]*src="([^"\n]+)"[^>]*>/);
212
+ if (sourceMatch) {
213
+ url = sourceMatch;
214
+ }
215
+ }
216
+ return url === null || url === void 0 ? void 0 : url[1];
217
+ };
218
+ /**
219
+ * 查找并解析媒体元素(img/video/iframe)
220
+ */ export var findImageElement = function(str) {
221
+ try {
222
+ // 首先尝试匹配包含 source 标签的 video 格式
223
+ var videoWithSourceMatch = str.match(/^\s*<video[^>\n]*>[\s\S]*?<source[^>]*src="([^"\n]+)"[^>]*>[\s\S]*?<\/video>\s*$/);
224
+ if (videoWithSourceMatch) {
225
+ var attrs = extractMediaAttributes(str);
226
+ return buildMediaElement(videoWithSourceMatch[1], 'video', attrs);
227
+ }
228
+ // 尝试匹配各种媒体标签格式
229
+ var patterns = [
230
+ /^\s*<(img|video|iframe)[^>\n]*>.*?<\/(?:img|video|iframe)>\s*$/,
231
+ /^\s*<(img|video|iframe)[^>\n]*\/?>(.*<\/(?:img|video|iframe)>)?\s*$/,
232
+ /^\s*<(img|video|iframe)[^>\n]*\/>\s*$/,
233
+ /^\s*<(img|video|iframe)[^>\n]*>\s*$/
234
+ ];
235
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
236
+ try {
237
+ for(var _iterator = patterns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
238
+ var pattern = _step.value;
239
+ var match = str.match(pattern);
240
+ if (match) {
241
+ var _match__match;
242
+ var tagName = (_match__match = match[0].match(/<(img|video|iframe)/)) === null || _match__match === void 0 ? void 0 : _match__match[1];
243
+ var url = extractVideoSource(match[0], tagName);
244
+ var attrs1 = extractMediaAttributes(match[0]);
245
+ return buildMediaElement(url, tagName, attrs1);
246
+ }
247
+ }
248
+ } catch (err) {
249
+ _didIteratorError = true;
250
+ _iteratorError = err;
251
+ } finally{
252
+ try {
253
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
254
+ _iterator.return();
255
+ }
256
+ } finally{
257
+ if (_didIteratorError) {
258
+ throw _iteratorError;
259
+ }
260
+ }
261
+ }
262
+ return null;
263
+ } catch (e) {
264
+ console.error('Failed to parse media element:', e);
265
+ return null;
266
+ }
267
+ };
268
+ /**
269
+ * 根据媒体元素信息创建编辑器节点
270
+ */ export var createMediaNodeFromElement = function(mediaElement) {
271
+ if (!mediaElement) return null;
272
+ // 根据标签类型确定媒体类型
273
+ var mediaTypeMap = {
274
+ video: 'video',
275
+ iframe: 'iframe',
276
+ img: 'image'
277
+ };
278
+ var mediaType = mediaTypeMap[mediaElement.tagName] || 'image';
279
+ return EditorUtils.createMediaNode(decodeURIComponentUrl(mediaElement.url || ''), mediaType, {
280
+ align: mediaElement.align,
281
+ alt: mediaElement.alt,
282
+ height: mediaElement.height,
283
+ width: mediaElement.width,
284
+ controls: mediaElement.controls,
285
+ autoplay: mediaElement.autoplay,
286
+ loop: mediaElement.loop,
287
+ muted: mediaElement.muted,
288
+ poster: mediaElement.poster
289
+ });
290
+ };
291
+ /**
292
+ * 标准 HTML 元素列表
293
+ * 这些标签会被正常解析为 HTML,其他标签会被当作普通文本处理
294
+ */ export var STANDARD_HTML_ELEMENTS = new Set([
295
+ // 文档结构
296
+ 'html',
297
+ 'head',
298
+ 'body',
299
+ 'title',
300
+ 'meta',
301
+ 'link',
302
+ 'style',
303
+ 'script',
304
+ // 内容分区
305
+ 'header',
306
+ 'nav',
307
+ 'main',
308
+ 'section',
309
+ 'article',
310
+ 'aside',
311
+ 'footer',
312
+ 'h1',
313
+ 'h2',
314
+ 'h3',
315
+ 'h4',
316
+ 'h5',
317
+ 'h6',
318
+ // 文本内容
319
+ 'div',
320
+ 'p',
321
+ 'hr',
322
+ 'pre',
323
+ 'blockquote',
324
+ // 列表
325
+ 'ul',
326
+ 'ol',
327
+ 'li',
328
+ 'dl',
329
+ 'dt',
330
+ 'dd',
331
+ // 表格
332
+ 'table',
333
+ 'thead',
334
+ 'tbody',
335
+ 'tfoot',
336
+ 'tr',
337
+ 'th',
338
+ 'td',
339
+ 'caption',
340
+ 'colgroup',
341
+ 'col',
342
+ // 表单
343
+ 'form',
344
+ 'input',
345
+ 'textarea',
346
+ 'button',
347
+ 'select',
348
+ 'option',
349
+ 'label',
350
+ 'fieldset',
351
+ 'legend',
352
+ // 内联文本语义
353
+ 'a',
354
+ 'em',
355
+ 'strong',
356
+ 'small',
357
+ 'mark',
358
+ 'del',
359
+ 'ins',
360
+ 'sub',
361
+ 'sup',
362
+ 'i',
363
+ 'b',
364
+ 'u',
365
+ 's',
366
+ 'code',
367
+ 'kbd',
368
+ 'samp',
369
+ 'var',
370
+ 'span',
371
+ 'br',
372
+ 'wbr',
373
+ // 图片和多媒体
374
+ 'img',
375
+ 'video',
376
+ 'audio',
377
+ 'source',
378
+ 'track',
379
+ 'iframe',
380
+ 'embed',
381
+ 'object',
382
+ 'param',
383
+ 'picture',
384
+ // 其他
385
+ 'canvas',
386
+ 'svg',
387
+ 'math',
388
+ 'details',
389
+ 'summary',
390
+ 'dialog',
391
+ 'menu',
392
+ 'menuitem',
393
+ // 字体
394
+ 'font'
395
+ ]);
396
+ /**
397
+ * 检查 HTML 标签是否为标准元素
398
+ * @param htmlString - HTML 字符串
399
+ * @returns 是否为标准 HTML 元素
400
+ */ export function isStandardHtmlElement(htmlString) {
401
+ // 提取标签名(支持开始标签和结束标签)
402
+ var tagMatch = htmlString.match(/<\/?(\w+)/);
403
+ if (!tagMatch) return false;
404
+ var tagName = tagMatch[1].toLowerCase();
405
+ return STANDARD_HTML_ELEMENTS.has(tagName);
406
+ }
407
+ /**
408
+ * 解析 HTML 注释中的上下文属性
409
+ */ var parseCommentContextProps = function(value, processedValue) {
410
+ var _processedValue_trim, _processedValue_trim1;
411
+ var isComment = value && (processedValue === null || processedValue === void 0 ? void 0 : (_processedValue_trim = processedValue.trim()) === null || _processedValue_trim === void 0 ? void 0 : _processedValue_trim.endsWith('-->')) && ((_processedValue_trim1 = processedValue.trim()) === null || _processedValue_trim1 === void 0 ? void 0 : _processedValue_trim1.startsWith('<!--'));
412
+ if (!isComment) {
413
+ return {};
414
+ }
415
+ try {
416
+ return json5.parse(value);
417
+ } catch (e) {
418
+ try {
419
+ return partialJsonParse(value);
420
+ } catch (parseError) {
421
+ console.warn('Failed to parse HTML comment as JSON or partial JSON:', {
422
+ value: value,
423
+ error: parseError
424
+ });
425
+ }
426
+ console.warn('HTML comment parse fallback attempted:', e);
427
+ }
428
+ return {};
429
+ };
430
+ /**
431
+ * 处理块级 HTML 元素
432
+ */ var handleBlockHtml = function(currentElement, processedValue, isUnclosedComment) {
433
+ var thinkElement = findThinkElement(currentElement.value);
434
+ if (thinkElement) {
435
+ return {
436
+ type: 'code',
437
+ language: 'think',
438
+ value: thinkElement.content,
439
+ children: [
440
+ {
441
+ text: thinkElement.content
442
+ }
443
+ ]
444
+ };
445
+ }
446
+ var answerElement = findAnswerElement(currentElement.value);
447
+ if (answerElement) {
448
+ return {
449
+ text: answerElement.content
450
+ };
451
+ }
452
+ var mediaElement = findImageElement(currentElement.value);
453
+ if (mediaElement) {
454
+ return createMediaNodeFromElement(mediaElement);
455
+ }
456
+ if (currentElement.value === '<br/>') {
457
+ return {
458
+ type: 'paragraph',
459
+ children: [
460
+ {
461
+ text: ''
462
+ }
463
+ ]
464
+ };
465
+ }
466
+ if (currentElement.value.match(/^<\/(img|video|iframe)>/)) {
467
+ return null;
468
+ }
469
+ var commentValue = isUnclosedComment ? processedValue : currentElement.value;
470
+ var isComment = commentValue.trim().startsWith('<!--') && commentValue.trim().endsWith('-->');
471
+ // 检查是否是 otherProps 序列化生成的 JSON 注释
472
+ // 这些注释应该被跳过,不应该被解析为 HTML 代码块
473
+ if (isComment) {
474
+ try {
475
+ var commentContent = commentValue.replace('<!--', '').replace('-->', '').trim();
476
+ var parsed = JSON.parse(commentContent);
477
+ // 如果能够成功解析为 JSON 对象,且是对象类型(不是数组或基本类型),
478
+ // 则认为是 otherProps 序列化生成的注释,应该返回 null 或空文本
479
+ // 这些注释应该在 parserMarkdownToSlateNode 中被跳过
480
+ if ((typeof parsed === "undefined" ? "undefined" : _type_of(parsed)) === 'object' && parsed !== null && !Array.isArray(parsed)) {
481
+ return {
482
+ text: ''
483
+ };
484
+ }
485
+ } catch (e) {
486
+ // 解析失败,不是 JSON 格式的注释,继续正常处理
487
+ }
488
+ }
489
+ if (isComment || isStandardHtmlElement(commentValue)) {
490
+ return commentValue.match(/<\/?(table|div|ul|li|ol|p|strong)[^\n>]*?>/) ? htmlToFragmentList(commentValue, '') : {
491
+ type: 'code',
492
+ language: 'html',
493
+ render: true,
494
+ value: commentValue,
495
+ children: [
496
+ {
497
+ text: commentValue
498
+ }
499
+ ]
500
+ };
501
+ }
502
+ return {
503
+ text: currentElement.value
504
+ };
505
+ };
506
+ /**
507
+ * 应用元素配置属性(纯函数版本)
508
+ */ var applyElementConfig = function(el, contextProps, processedValue, isUnclosedComment, currentElement) {
509
+ var _valueToCheck_trim;
510
+ if (!el || Array.isArray(el)) {
511
+ return el;
512
+ }
513
+ var isPlainText = 'text' in el && Object.keys(el).length === 1;
514
+ if (isPlainText) {
515
+ return el;
516
+ }
517
+ var valueToCheck = isUnclosedComment ? processedValue : currentElement === null || currentElement === void 0 ? void 0 : currentElement.value;
518
+ var otherProps = _object_spread({}, contextProps);
519
+ // 只有当 finished === false 时才设置 finished 属性,否则删除
520
+ if (isUnclosedComment) {
521
+ otherProps.finished = false;
522
+ }
523
+ var result = _object_spread_props(_object_spread({}, el), {
524
+ isConfig: valueToCheck === null || valueToCheck === void 0 ? void 0 : (_valueToCheck_trim = valueToCheck.trim()) === null || _valueToCheck_trim === void 0 ? void 0 : _valueToCheck_trim.startsWith('<!--')
525
+ });
526
+ // 只有当 otherProps 有内容时才设置,避免类型错误
527
+ if (Object.keys(otherProps).length > 0) {
528
+ result.otherProps = otherProps;
529
+ }
530
+ return result;
531
+ };
532
+ /**
533
+ * 处理 span 标签的样式属性(纯函数版本)
534
+ */ var processSpanTag = function(str, tag, htmlTag) {
535
+ try {
536
+ var styles = str.match(/style="([^"\n]+)"/);
537
+ if (!styles) {
538
+ return htmlTag;
539
+ }
540
+ var stylesMap = new Map(styles[1].split(';').map(function(item) {
541
+ return item.split(':').map(function(item) {
542
+ return item.trim();
543
+ });
544
+ }));
545
+ var color = stylesMap.get('color');
546
+ if (color) {
547
+ return _to_consumable_array(htmlTag).concat([
548
+ {
549
+ tag: tag,
550
+ color: color
551
+ }
552
+ ]);
553
+ }
554
+ } catch (e) {
555
+ console.warn('Failed to parse span style attribute:', {
556
+ str: str,
557
+ error: e
558
+ });
559
+ }
560
+ return htmlTag;
561
+ };
562
+ /**
563
+ * 处理 a 标签的链接属性(纯函数版本)
564
+ */ var processATag = function(str, tag, htmlTag) {
565
+ var url = str.match(/href="([\w:./_\-#\\]+)"/);
566
+ if (url) {
567
+ return _to_consumable_array(htmlTag).concat([
568
+ {
569
+ tag: tag,
570
+ url: url[1]
571
+ }
572
+ ]);
573
+ }
574
+ return htmlTag;
575
+ };
576
+ /**
577
+ * 处理 font 标签的颜色属性(纯函数版本)
578
+ */ var processFontTag = function(str, tag, htmlTag) {
579
+ var colorMatch = str.match(/color="([^"\n]+)"/) || str.match(/color=([^"\n]+)/);
580
+ if (colorMatch) {
581
+ return _to_consumable_array(htmlTag).concat([
582
+ {
583
+ tag: tag,
584
+ color: colorMatch[1].replaceAll('>', '')
585
+ }
586
+ ]);
587
+ }
588
+ return htmlTag;
589
+ };
590
+ /**
591
+ * HTML 标签处理器映射表
592
+ */ var htmlTagProcessors = {
593
+ span: processSpanTag,
594
+ a: processATag,
595
+ font: processFontTag
596
+ };
597
+ /**
598
+ * 处理HTML标签并添加到标签栈中(纯函数版本)
599
+ * @param str - HTML标签字符串
600
+ * @param tag - 标签名称
601
+ * @param htmlTag - HTML标签栈
602
+ * @returns 返回新的标签栈数组
603
+ */ var processHtmlTag = function(str, tag, htmlTag) {
604
+ var processor = htmlTagProcessors[tag];
605
+ if (processor) {
606
+ return processor(str, tag, htmlTag);
607
+ }
608
+ return _to_consumable_array(htmlTag).concat([
609
+ {
610
+ tag: tag
611
+ }
612
+ ]);
613
+ };
614
+ /**
615
+ * 处理内联HTML元素(纯函数版本)
616
+ * @param currentElement - 当前处理的HTML元素
617
+ * @param htmlTag - HTML标签栈
618
+ * @returns 返回处理后的元素对象和新的标签栈,如果是标签则返回null
619
+ */ var processInlineHtml = function(currentElement, htmlTag) {
620
+ var value = currentElement.value;
621
+ if (value.match(/<br\/?>/)) {
622
+ return {
623
+ el: {
624
+ type: 'break',
625
+ children: [
626
+ {
627
+ text: '\n'
628
+ }
629
+ ]
630
+ },
631
+ htmlTag: htmlTag
632
+ };
633
+ }
634
+ var answerElement = findAnswerElement(value);
635
+ if (answerElement) {
636
+ return {
637
+ el: {
638
+ text: answerElement.content
639
+ },
640
+ htmlTag: htmlTag
641
+ };
642
+ }
643
+ if (!isStandardHtmlElement(value)) {
644
+ return {
645
+ el: {
646
+ text: value
647
+ },
648
+ htmlTag: htmlTag
649
+ };
650
+ }
651
+ var htmlMatch = value.match(/<\/?(b|i|del|font|code|span|sup|sub|strong|a)[^\n>]*?>/);
652
+ if (htmlMatch) {
653
+ var _htmlMatch = _sliced_to_array(htmlMatch, 2), str = _htmlMatch[0], tag = _htmlMatch[1];
654
+ var isClosingTag = str.startsWith('</');
655
+ var isMatchingTag = isClosingTag && htmlTag.length && htmlTag[htmlTag.length - 1].tag === tag;
656
+ var newHtmlTag = htmlTag;
657
+ if (isMatchingTag) {
658
+ newHtmlTag = htmlTag.slice(0, -1);
659
+ }
660
+ if (!isClosingTag) {
661
+ newHtmlTag = processHtmlTag(str, tag, newHtmlTag);
662
+ }
663
+ return {
664
+ el: null,
665
+ htmlTag: newHtmlTag
666
+ };
667
+ }
668
+ var mediaElement = findImageElement(value);
669
+ return {
670
+ el: mediaElement ? createMediaNodeFromElement(mediaElement) : {
671
+ text: value
672
+ },
673
+ htmlTag: htmlTag
674
+ };
675
+ };
676
+ /**
677
+ * 查找附件链接
678
+ */ export var findAttachment = function(str) {
679
+ try {
680
+ var match = str.match(/^\s*<a[^>\n]*download[^>\n]*\/?>(.*<\/a>:?)?\s*$/);
681
+ if (match) {
682
+ var url = match[0].match(/href="([^"\n]+)"/);
683
+ var size = match[0].match(/data-size="(\d+)"/);
684
+ if (url) {
685
+ return {
686
+ url: url[1],
687
+ size: Number((size === null || size === void 0 ? void 0 : size[1]) || 0)
688
+ };
689
+ }
690
+ }
691
+ return null;
692
+ } catch (e) {
693
+ return null;
694
+ }
695
+ };
696
+ /**
697
+ * 处理HTML节点
698
+ * @param currentElement - 当前处理的HTML元素
699
+ * @param parent - 父级元素,用于判断上下文
700
+ * @param htmlTag - HTML标签栈,用于跟踪嵌套的HTML标签
701
+ * @returns 返回包含解析后元素和上下文属性的对象
702
+ */ export var handleHtml = function(currentElement, parent, htmlTag) {
703
+ var _currentElement_value;
704
+ var trimmedValue = (currentElement === null || currentElement === void 0 ? void 0 : (_currentElement_value = currentElement.value) === null || _currentElement_value === void 0 ? void 0 : _currentElement_value.trim()) || '';
705
+ var isUnclosedComment = trimmedValue.startsWith('<!--') && !trimmedValue.endsWith('-->');
706
+ var processedValue = isUnclosedComment ? trimmedValue + '-->' : (currentElement === null || currentElement === void 0 ? void 0 : currentElement.value) || '';
707
+ var value = (processedValue === null || processedValue === void 0 ? void 0 : processedValue.replace('<!--', '').replace('-->', '').trim()) || '{}';
708
+ var contextProps = parseCommentContextProps(value, processedValue);
709
+ var isBlockLevel = !parent || [
710
+ 'listItem',
711
+ 'blockquote'
712
+ ].includes(parent.type);
713
+ var el;
714
+ var updatedHtmlTag = htmlTag;
715
+ if (isBlockLevel) {
716
+ el = handleBlockHtml(currentElement, processedValue, isUnclosedComment);
717
+ } else {
718
+ var inlineResult = processInlineHtml(currentElement, htmlTag);
719
+ el = inlineResult.el;
720
+ updatedHtmlTag = inlineResult.htmlTag;
721
+ }
722
+ var configuredEl = applyElementConfig(el, contextProps, processedValue, isUnclosedComment, currentElement);
723
+ return {
724
+ el: configuredEl,
725
+ contextProps: contextProps,
726
+ htmlTag: updatedHtmlTag
727
+ };
728
+ };
729
+ /**
730
+ * 预处理特殊标签(think/answer),将其转换为代码块格式
731
+ * @param markdown - 原始 Markdown 字符串
732
+ * @param tagName - 标签名称(think 或 answer)
733
+ * @returns 处理后的 Markdown 字符串
734
+ */ export function preprocessSpecialTags(markdown, tagName) {
735
+ var tagRegex = new RegExp("<".concat(tagName, ">([\\s\\S]*?)<\\/").concat(tagName, ">"), 'g');
736
+ return markdown === null || markdown === void 0 ? void 0 : markdown.replace(tagRegex, function(match, content) {
737
+ var trimmedContent = content.trim();
738
+ // 如果内容中包含代码块标记(三个反引号),需要进行转义
739
+ // 策略:使用特殊标记替换代码块,保持原始格式
740
+ var processedContent = trimmedContent === null || trimmedContent === void 0 ? void 0 : trimmedContent.replace(/```(\w*)\n?([\s\S]*?)```/g, function(_, lang, code) {
741
+ // 使用特殊标记包裹,保留语言和代码内容
742
+ // 格式:【CODE_BLOCK:lang】code【/CODE_BLOCK】
743
+ var marker = '\u200B'; // 零宽空格,用于标记
744
+ return "".concat(marker, "【CODE_BLOCK:").concat(lang || '', "】\n").concat(code, "\n【/CODE_BLOCK】").concat(marker);
745
+ });
746
+ // 构建对应类型的代码块
747
+ return "```".concat(tagName, "\n").concat(processedContent, "\n```");
748
+ });
749
+ }
750
+ /**
751
+ * 预处理 <think> 标签,将其转换为 ```think 代码块格式
752
+ * @param markdown - 原始 Markdown 字符串
753
+ * @returns 处理后的 Markdown 字符串
754
+ */ export function preprocessThinkTags(markdown) {
755
+ return preprocessSpecialTags(markdown, 'think');
756
+ }
757
+ /**
758
+ * 预处理所有非标准 HTML 标签,提取其内容(删除标签本身)
759
+ * @param markdown - 原始 Markdown 字符串
760
+ * @returns 处理后的 Markdown 字符串
761
+ */ export function preprocessNonStandardHtmlTags(markdown) {
762
+ var result = markdown;
763
+ var hasNonStandardTags = true;
764
+ // 循环处理,直到没有非标准标签(处理嵌套情况)
765
+ while(hasNonStandardTags){
766
+ var before = result;
767
+ // 匹配所有 HTML 标签对:<tagname>content</tagname>
768
+ result = result.replace(/<(\w+)>([\s\S]*?)<\/\1>/g, function(match, tagName, content) {
769
+ // 检查是否为标准 HTML 元素
770
+ if (STANDARD_HTML_ELEMENTS.has(tagName.toLowerCase())) {
771
+ // 标准元素保持不变
772
+ return match;
773
+ }
774
+ // 非标准元素只保留内容(不 trim,保持原始格式)
775
+ return content;
776
+ });
777
+ // 如果没有变化,说明处理完成
778
+ hasNonStandardTags = before !== result;
779
+ }
780
+ return result;
781
+ }