markdown-flow-ui 0.1.92 → 0.1.93-beta.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 (108) hide show
  1. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js +1 -1
  2. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js.map +1 -1
  3. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
  4. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
  5. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
  6. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.cjs.js +6 -0
  7. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.cjs.js.map +1 -0
  8. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.es.js +350 -0
  9. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.es.js.map +1 -0
  10. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.cjs.js +1 -1
  11. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.es.js +1 -1
  12. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.cjs.js +1 -1
  13. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.es.js +1 -1
  14. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.cjs.js +1 -1
  15. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.es.js +1 -1
  16. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.cjs.js +1 -1
  17. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.es.js +1 -1
  18. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.cjs.js +1 -1
  19. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.es.js +1 -1
  20. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.cjs.js +1 -1
  21. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.es.js +1 -1
  22. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.cjs.js +1 -1
  23. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
  24. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js +1 -1
  25. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js +1 -1
  26. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.cjs.js +1 -1
  27. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.es.js +1 -1
  28. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/index.cjs.js +1 -1
  29. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/index.es.js +1 -1
  30. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.cjs.js +1 -1
  31. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.es.js +1 -1
  32. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.cjs.js +1 -1
  33. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.es.js +1 -1
  34. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.cjs.js +1 -1
  35. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.es.js +1 -1
  36. package/dist/_virtual/index.cjs10.js +1 -1
  37. package/dist/_virtual/index.cjs2.js +1 -1
  38. package/dist/_virtual/index.cjs3.js +1 -1
  39. package/dist/_virtual/index.cjs4.js +1 -1
  40. package/dist/_virtual/index.cjs7.js +1 -1
  41. package/dist/_virtual/index.cjs8.js +1 -1
  42. package/dist/_virtual/index.es10.js +2 -2
  43. package/dist/_virtual/index.es2.js +5 -2
  44. package/dist/_virtual/index.es2.js.map +1 -1
  45. package/dist/_virtual/index.es3.js +2 -4
  46. package/dist/_virtual/index.es3.js.map +1 -1
  47. package/dist/_virtual/index.es4.js +4 -5
  48. package/dist/_virtual/index.es4.js.map +1 -1
  49. package/dist/_virtual/index.es7.js +2 -3
  50. package/dist/_virtual/index.es7.js.map +1 -1
  51. package/dist/_virtual/index.es8.js +3 -2
  52. package/dist/_virtual/index.es8.js.map +1 -1
  53. package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
  54. package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
  55. package/dist/components/ContentRender/ContentRender.es.js +111 -104
  56. package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
  57. package/dist/components/ContentRender/ContentRender.stories.d.ts +1 -0
  58. package/dist/components/ContentRender/IframeSandbox.cjs.js +6 -5
  59. package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
  60. package/dist/components/ContentRender/IframeSandbox.es.js +104 -98
  61. package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
  62. package/dist/components/ContentRender/SandboxApp.cjs.js +3 -2
  63. package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
  64. package/dist/components/ContentRender/SandboxApp.es.js +92 -84
  65. package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
  66. package/dist/components/ContentRender/blackboard/blackboard-runtime.cjs.js +5 -0
  67. package/dist/components/ContentRender/blackboard/blackboard-runtime.cjs.js.map +1 -0
  68. package/dist/components/ContentRender/blackboard/blackboard-runtime.d.ts +18 -0
  69. package/dist/components/ContentRender/blackboard/blackboard-runtime.es.js +137 -0
  70. package/dist/components/ContentRender/blackboard/blackboard-runtime.es.js.map +1 -0
  71. package/dist/components/ContentRender/blackboard/diff-parser.cjs.js +2 -0
  72. package/dist/components/ContentRender/blackboard/diff-parser.cjs.js.map +1 -0
  73. package/dist/components/ContentRender/blackboard/diff-parser.d.ts +8 -0
  74. package/dist/components/ContentRender/blackboard/diff-parser.es.js +132 -0
  75. package/dist/components/ContentRender/blackboard/diff-parser.es.js.map +1 -0
  76. package/dist/components/ContentRender/blackboard/diff-parser.test.d.ts +1 -0
  77. package/dist/components/ContentRender/blackboard-vendor.cjs.js +2 -0
  78. package/dist/components/ContentRender/blackboard-vendor.cjs.js.map +1 -0
  79. package/dist/components/ContentRender/blackboard-vendor.d.ts +5 -0
  80. package/dist/components/ContentRender/blackboard-vendor.es.js +15 -0
  81. package/dist/components/ContentRender/blackboard-vendor.es.js.map +1 -0
  82. package/dist/components/ContentRender/index.cjs.js +1 -1
  83. package/dist/components/ContentRender/index.es.js +1 -0
  84. package/dist/components/ContentRender/index.es.js.map +1 -1
  85. package/dist/components/ContentRender/utils/split-content.cjs.js +2 -2
  86. package/dist/components/ContentRender/utils/split-content.cjs.js.map +1 -1
  87. package/dist/components/ContentRender/utils/split-content.es.js +118 -109
  88. package/dist/components/ContentRender/utils/split-content.es.js.map +1 -1
  89. package/dist/components/ContentRender/vendor/daisyui-v4.min.css.cjs.js +22 -0
  90. package/dist/components/ContentRender/vendor/daisyui-v4.min.css.cjs.js.map +1 -0
  91. package/dist/components/ContentRender/vendor/daisyui-v4.min.css.es.js +25 -0
  92. package/dist/components/ContentRender/vendor/daisyui-v4.min.css.es.js.map +1 -0
  93. package/dist/components/ContentRender/vendor/gsap-v3.min.cjs.js +12 -0
  94. package/dist/components/ContentRender/vendor/gsap-v3.min.cjs.js.map +1 -0
  95. package/dist/components/ContentRender/vendor/gsap-v3.min.es.js +15 -0
  96. package/dist/components/ContentRender/vendor/gsap-v3.min.es.js.map +1 -0
  97. package/dist/components/ContentRender/vendor/tailwindcss-v3.min.cjs.js +2 -0
  98. package/dist/components/ContentRender/vendor/tailwindcss-v3.min.cjs.js.map +1 -0
  99. package/dist/components/ContentRender/vendor/tailwindcss-v3.min.es.js +5 -0
  100. package/dist/components/ContentRender/vendor/tailwindcss-v3.min.es.js.map +1 -0
  101. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js +1 -1
  102. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js.map +1 -1
  103. package/dist/components/MarkdownFlow/MarkdownFlow.es.js +3 -2
  104. package/dist/components/MarkdownFlow/MarkdownFlow.es.js.map +1 -1
  105. package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
  106. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  107. package/dist/markdown-flow-ui-lib.css +1 -1
  108. package/package.json +4 -1
@@ -1,108 +1,117 @@
1
- const $ = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\s>]/i, C = [
1
+ const U = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\s>]/i, V = [
2
2
  /<svg[\s\S]*?<\/svg>/i,
3
3
  /<img\b[^>]*?>/i,
4
4
  /```mermaid[\s\S]*?```/i,
5
5
  /```[a-zA-Z0-9]+[\s\S]*?```/i
6
- ], _ = /!\[[^\]]*]\([^\s)\n]+(?:\s+"[^"]*")?\)/i, k = /<iframe\b[^>]*\bdata-tag\s*=\s*(["'])video\1[^>]*>[\s\S]*?<\/iframe>/i, O = /<\/[a-z][^>]*>\s*\n(?=[^\s<])/gi, T = /<custom-button-after-content\b[\s\S]*?<\/custom-button-after-content>/gi, V = /^"[\s\S]*"$/, U = /```mermaid[\s\S]*?```/i, w = (s) => s.split(/\r?\n/).map((e) => e.trim()).find(Boolean) ?? "", W = (s) => {
7
- const e = s.indexOf("```");
8
- if (e === -1) return null;
9
- const t = s.indexOf("```", e + 3);
6
+ ], O = /!\[[^\]]*]\([^\s)\n]+(?:\s+"[^"]*")?\)/i, S = /<iframe\b[^>]*\bdata-tag\s*=\s*(["'])video\1[^>]*>[\s\S]*?<\/iframe>/i, K = /!\+\+\+/i, P = /<\/[a-z][^>]*>\s*\n(?=[^\s<])/gi, D = /<custom-button-after-content\b[\s\S]*?<\/custom-button-after-content>/gi, W = /^"[\s\S]*"$/, Q = /```mermaid[\s\S]*?```/i, F = (s) => s.split(/\r?\n/).map((n) => n.trim()).find(Boolean) ?? "", X = (s) => {
7
+ const n = s.indexOf("```");
8
+ if (n === -1) return null;
9
+ const t = s.indexOf("```", n + 3);
10
10
  return t === -1 ? {
11
- start: e,
12
- block: s.slice(e),
11
+ start: n,
12
+ block: s.slice(n),
13
13
  complete: !1
14
14
  } : {
15
- start: e,
15
+ start: n,
16
16
  end: t + 3,
17
- block: s.slice(e, t + 3),
17
+ block: s.slice(n, t + 3),
18
18
  complete: !0
19
19
  };
20
- }, K = (s) => {
21
- const e = s.split(/\r?\n/).map((t) => t.trim()).filter(Boolean);
22
- return e.length <= 1 ? s : e[0];
23
- }, Q = (s, e) => {
24
- if (!V.test(s)) return s;
20
+ }, j = (s) => {
21
+ const n = s.split(/\r?\n/).map((t) => t.trim()).filter(Boolean);
22
+ return n.length <= 1 ? s : n[0];
23
+ }, G = (s, n) => {
24
+ if (!W.test(s)) return s;
25
25
  const t = s.slice(1, -1);
26
- if (!e) return t;
27
- const n = t.match(U);
28
- if (!n || typeof n.index != "number")
26
+ if (!n) return t;
27
+ const e = t.match(Q);
28
+ if (!e || typeof e.index != "number")
29
29
  return t;
30
- const o = t.slice(0, n.index), c = t.slice(n.index + n[0].length), r = w(o), i = w(c);
31
- return !r || !i ? t : `${r}${n[0]}${i}`;
32
- }, X = (s) => {
33
- const e = [], t = /```/g;
34
- let n;
35
- for (; (n = t.exec(s)) !== null; ) {
36
- const o = n.index, c = t.exec(s);
30
+ const o = t.slice(0, e.index), c = t.slice(e.index + e[0].length), r = F(o), i = F(c);
31
+ return !r || !i ? t : `${r}${e[0]}${i}`;
32
+ }, H = (s) => {
33
+ const n = [], t = /```/g;
34
+ let e;
35
+ for (; (e = t.exec(s)) !== null; ) {
36
+ const o = e.index, c = t.exec(s);
37
37
  if (!c) {
38
- e.push({ start: o, end: s.length });
38
+ n.push({ start: o, end: s.length });
39
39
  break;
40
40
  }
41
- e.push({ start: o, end: c.index + 3 });
41
+ n.push({ start: o, end: c.index + 3 });
42
42
  }
43
- return e;
44
- }, j = (s, e) => e.some(({ start: t, end: n }) => s >= t && s < n), x = (s, e, t) => {
45
- const n = e.flags.includes("g") ? e.flags : `${e.flags}g`, o = new RegExp(e.source, n);
43
+ return n;
44
+ }, Z = (s, n) => n.some(({ start: t, end: e }) => s >= t && s < e), g = (s, n, t) => {
45
+ const e = n.flags.includes("g") ? n.flags : `${n.flags}g`, o = new RegExp(n.source, e);
46
46
  let c;
47
47
  for (; (c = o.exec(s)) !== null; )
48
- if (!j(c.index, t))
48
+ if (!Z(c.index, t))
49
49
  return c.index;
50
50
  return -1;
51
- }, G = (s, e) => {
52
- let t = s.length, n;
53
- for (O.lastIndex = 0; n = O.exec(s); )
54
- if (!(n.index <= e)) {
55
- t = n.index + n[0].length;
51
+ }, q = (s, n) => {
52
+ let t = s.length, e;
53
+ for (P.lastIndex = 0; e = P.exec(s); )
54
+ if (!(e.index <= n)) {
55
+ t = e.index + e[0].length;
56
56
  break;
57
57
  }
58
58
  return t;
59
- }, H = (s) => {
59
+ }, J = (s) => {
60
60
  if (!s.length) return s;
61
- const e = [];
61
+ const n = [];
62
62
  return s.forEach((t) => {
63
63
  if (t.type !== "sandbox") {
64
- e.push(t);
64
+ n.push(t);
65
65
  return;
66
66
  }
67
- T.lastIndex = 0;
68
- let n = 0, o;
69
- for (; (o = T.exec(t.value)) !== null; ) {
70
- const r = t.value.slice(n, o.index);
71
- r.trim() && e.push({ type: "sandbox", value: r }), e.push({ type: "markdown", value: o[0] }), n = o.index + o[0].length;
67
+ D.lastIndex = 0;
68
+ let e = 0, o;
69
+ for (; (o = D.exec(t.value)) !== null; ) {
70
+ const r = t.value.slice(e, o.index);
71
+ r.trim() && n.push({ type: "sandbox", value: r }), n.push({ type: "markdown", value: o[0] }), e = o.index + o[0].length;
72
72
  }
73
- const c = t.value.slice(n);
74
- c.trim() && e.push({ type: "sandbox", value: c });
75
- }), e;
76
- }, Z = (s) => {
77
- let e = null;
78
- return C.forEach((t) => {
79
- const n = t.exec(s);
80
- if (!n || typeof n.index != "number") return;
81
- const o = n.index, c = n.index + n[0].length;
82
- (!e || o < e.start) && (e = { start: o, end: c });
83
- }), e;
84
- }, q = (...s) => s.reduce((e, t) => t && (!e || t.start < e.start) ? t : e, null), P = (s, e) => {
85
- const t = x(
73
+ const c = t.value.slice(e);
74
+ c.trim() && n.push({ type: "sandbox", value: c });
75
+ }), n;
76
+ }, Y = (s) => {
77
+ let n = null;
78
+ return V.forEach((t) => {
79
+ const e = t.exec(s);
80
+ if (!e || typeof e.index != "number") return;
81
+ const o = e.index, c = e.index + e[0].length;
82
+ (!n || o < n.start) && (n = { start: o, end: c });
83
+ }), n;
84
+ }, tt = (...s) => s.reduce((n, t) => t && (!n || t.start < n.start) ? t : n, null), w = (s, n) => {
85
+ const t = g(
86
+ s,
87
+ O,
88
+ n
89
+ );
90
+ if (t === -1) return null;
91
+ const e = s.slice(t).match(O);
92
+ return e ? { start: t, end: t + e[0].length } : null;
93
+ }, nt = (s, n) => {
94
+ const t = g(
86
95
  s,
87
- _,
88
- e
96
+ S,
97
+ n
89
98
  );
90
99
  if (t === -1) return null;
91
- const n = s.slice(t).match(_);
92
- return n ? { start: t, end: t + n[0].length } : null;
93
- }, J = (s, e) => {
94
- const t = x(
100
+ const e = s.slice(t).match(S);
101
+ return e ? { start: t, end: t + e[0].length } : null;
102
+ }, et = (s, n) => {
103
+ const t = g(
95
104
  s,
96
- k,
97
- e
105
+ K,
106
+ n
98
107
  );
99
108
  if (t === -1) return null;
100
- const n = s.slice(t).match(k);
101
- return n ? { start: t, end: t + n[0].length } : null;
102
- }, Y = (s) => k.test(s.trim()), tt = (s) => {
103
- const e = s.match(/^\s*\|.+\|\s*$/m);
104
- if (!e || typeof e.index != "number") return null;
105
- const t = e[0].match(/^\s*/)?.[0].length ?? 0, n = e.index + t, o = s.slice(n).split(`
109
+ const e = s.indexOf("!+++", t + 4), o = e === -1 ? s.length : e + 4;
110
+ return { start: t, end: o };
111
+ }, st = (s) => S.test(s.trim()), ot = (s) => {
112
+ const n = s.match(/^\s*\|.+\|\s*$/m);
113
+ if (!n || typeof n.index != "number") return null;
114
+ const t = n[0].match(/^\s*/)?.[0].length ?? 0, e = n.index + t, o = s.slice(e).split(`
106
115
  `), c = [];
107
116
  for (const i of o) {
108
117
  if (!i.trim().startsWith("|")) break;
@@ -110,63 +119,63 @@ const $ = /<(script|style|link|iframe|html|head|body|meta|title|base|template|di
110
119
  }
111
120
  const r = c.join(`
112
121
  `);
113
- return { start: n, block: r, end: n + r.length };
114
- }, f = (s, e = !1) => {
115
- const t = Q(s, e), n = (l) => H(l), o = W(t);
122
+ return { start: e, block: r, end: e + r.length };
123
+ }, h = (s, n = !1) => {
124
+ const t = G(s, n), e = (l) => J(l), o = X(t);
116
125
  if (o) {
117
126
  if (!o.complete)
118
- return n(e ? [{ type: "markdown", value: t }] : [{ type: "markdown", value: o.block }]);
119
- if (!e)
120
- return n([{ type: "markdown", value: o.block }]);
121
- const l = [], a = t.slice(0, o.start), u = K(a);
127
+ return e(n ? [{ type: "markdown", value: t }] : [{ type: "markdown", value: o.block }]);
128
+ if (!n)
129
+ return e([{ type: "markdown", value: o.block }]);
130
+ const l = [], a = t.slice(0, o.start), u = j(a);
122
131
  u.trim() && l.push({ type: "text", value: u }), l.push({ type: "markdown", value: o.block });
123
- const d = t.slice(o.end);
124
- return d.trim() && l.push(...f(d, !0)), n(l);
132
+ const f = t.slice(o.end);
133
+ return f.trim() && l.push(...h(f, !0)), e(l);
125
134
  }
126
- const c = X(t), r = x(
135
+ const c = H(t), r = g(
127
136
  t,
128
- $,
137
+ U,
129
138
  c
130
- ), i = x(
139
+ ), i = g(
131
140
  t,
132
141
  /<svg\b/i,
133
142
  c
134
- ), I = r !== -1 && i !== -1 && r < i, S = P(t, c), z = !!S && i !== -1 && S.start < i;
143
+ ), I = r !== -1 && i !== -1 && r < i, M = w(t, c), z = !!M && i !== -1 && M.start < i;
135
144
  if (i !== -1 && !I && !z) {
136
- const l = t.slice(0, i), a = t.indexOf("</svg>", i), u = a === -1 ? `${t.slice(i)}</svg>` : t.slice(i, a + 6), d = a === -1 ? "" : t.slice(a + 6);
137
- if (e) {
138
- const b = [];
139
- return l.trim() && b.push({ type: "text", value: l }), b.push({ type: "markdown", value: u }), d.trim() && b.push(...f(d, !0)), n(b);
145
+ const l = t.slice(0, i), a = t.indexOf("</svg>", i), u = a === -1 ? `${t.slice(i)}</svg>` : t.slice(i, a + 6), f = a === -1 ? "" : t.slice(a + 6);
146
+ if (n) {
147
+ const v = [];
148
+ return l.trim() && v.push({ type: "text", value: l }), v.push({ type: "markdown", value: u }), f.trim() && v.push(...h(f, !0)), e(v);
140
149
  }
141
150
  if (a === -1)
142
- return n([{ type: "markdown", value: u }]);
151
+ return e([{ type: "markdown", value: u }]);
143
152
  }
144
- const h = tt(t);
145
- if (h) {
146
- const l = [], a = t.slice(0, h.start);
147
- e && a.trim() && l.push(...f(a, !0)), l.push({ type: "markdown", value: h.block });
148
- const u = t.slice(h.end), d = u.length < t.length;
149
- return u.trim() && d && l.push(
150
- ...e ? f(u, !0) : f(u)
151
- ), n(l);
153
+ const p = ot(t);
154
+ if (p) {
155
+ const l = [], a = t.slice(0, p.start);
156
+ n && a.trim() && l.push(...h(a, !0)), l.push({ type: "markdown", value: p.block });
157
+ const u = t.slice(p.end), f = u.length < t.length;
158
+ return u.trim() && f && l.push(
159
+ ...n ? h(u, !0) : h(u)
160
+ ), e(l);
152
161
  }
153
- const F = Z(t), D = P(t, c), L = J(
162
+ const L = Y(t), C = w(t, c), $ = nt(
154
163
  t,
155
164
  c
156
- ), m = q(
157
- F,
158
- D,
159
- L
165
+ ), m = et(t, c), d = tt(
166
+ L,
167
+ C,
168
+ $
160
169
  );
161
- if (r === -1 && !m)
162
- return e && t.trim() ? n([{ type: "text", value: t }]) : [];
163
- const g = !!m && (r === -1 || m.start <= r), v = g ? m.start : r, y = g ? m.end : G(t, v), p = [], E = t.slice(0, v), M = t.slice(v, y), B = g && Y(M), A = B ? E.trimEnd() : E, R = t.slice(y), N = B ? R.trimStart() : R;
164
- return e && A.trim() && p.push({ type: "text", value: A }), p.push({
165
- type: g ? "markdown" : "sandbox",
166
- value: M
167
- }), N.trim() && p.push(...f(N, e)), n(p);
170
+ if (r === -1 && !d && !m)
171
+ return n && t.trim() ? e([{ type: "text", value: t }]) : [];
172
+ const x = !!d && (r === -1 || d.start <= r), E = !!m && (r === -1 || m.start <= r) && (!d || m.start <= d.start), k = E ? m.start : x ? d.start : r, y = E ? m.end : x ? d.end : q(t, k), b = [], B = t.slice(0, k), A = t.slice(k, y), R = x && st(A), T = R ? B.trimEnd() : B, _ = t.slice(y), N = R ? _.trimStart() : _;
173
+ return n && T.trim() && b.push({ type: "text", value: T }), b.push({
174
+ type: x ? "markdown" : "sandbox",
175
+ value: A
176
+ }), N.trim() && b.push(...h(N, n)), e(b);
168
177
  };
169
178
  export {
170
- f as splitContentSegments
179
+ h as splitContentSegments
171
180
  };
172
181
  //# sourceMappingURL=split-content.es.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"split-content.es.js","sources":["../../../../src/components/ContentRender/utils/split-content.ts"],"sourcesContent":["export type RenderSegment =\n | { type: \"markdown\"; value: string }\n | { type: \"sandbox\"; value: string }\n | { type: \"text\"; value: string };\n\nconst SANDBOX_START_PATTERN =\n /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\\s>]/i;\n\nconst INLINE_SANDBOX_PATTERNS: RegExp[] = [\n /<svg[\\s\\S]*?<\\/svg>/i,\n /<img\\b[^>]*?>/i,\n /```mermaid[\\s\\S]*?```/i,\n /```[a-zA-Z0-9]+[\\s\\S]*?```/i,\n];\nconst MARKDOWN_IMAGE_PATTERN = /!\\[[^\\]]*]\\([^\\s)\\n]+(?:\\s+\"[^\"]*\")?\\)/i;\nconst MARKDOWN_VIDEO_IFRAME_PATTERN =\n /<iframe\\b[^>]*\\bdata-tag\\s*=\\s*([\"'])video\\1[^>]*>[\\s\\S]*?<\\/iframe>/i;\n\nconst closingBoundary = /<\\/[a-z][^>]*>\\s*\\n(?=[^\\s<])/gi;\nconst CUSTOM_BUTTON_PATTERN =\n /<custom-button-after-content\\b[\\s\\S]*?<\\/custom-button-after-content>/gi;\n\ntype MatchResult = { start: number; end: number };\ntype FenceRange = { start: number; end: number };\ntype FenceBlock =\n | { start: number; end: number; block: string; complete: true }\n | { start: number; block: string; complete: false };\n\nconst WRAPPED_QUOTES_PATTERN = /^\"[\\s\\S]*\"$/;\nconst MERMAID_BLOCK_PATTERN = /```mermaid[\\s\\S]*?```/i;\n\nconst firstNonEmptyLine = (content: string) =>\n content\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find(Boolean) ?? \"\";\n\nconst extractFirstFenceBlock = (raw: string): FenceBlock | null => {\n const start = raw.indexOf(\"```\");\n if (start === -1) return null;\n\n const closing = raw.indexOf(\"```\", start + 3);\n if (closing === -1) {\n return {\n start,\n block: raw.slice(start),\n complete: false,\n };\n }\n\n return {\n start,\n end: closing + 3,\n block: raw.slice(start, closing + 3),\n complete: true,\n };\n};\n\nconst normalizeBeforeFenceText = (before: string) => {\n const nonEmptyLines = before\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter(Boolean);\n\n if (nonEmptyLines.length <= 1) return before;\n return nonEmptyLines[0];\n};\n\nconst normalizeQuotedMermaidContent = (raw: string, keepText: boolean) => {\n if (!WRAPPED_QUOTES_PATTERN.test(raw)) return raw;\n\n const unwrapped = raw.slice(1, -1);\n if (!keepText) return unwrapped;\n\n const mermaidMatch = unwrapped.match(MERMAID_BLOCK_PATTERN);\n if (!mermaidMatch || typeof mermaidMatch.index !== \"number\") {\n return unwrapped;\n }\n\n const before = unwrapped.slice(0, mermaidMatch.index);\n const after = unwrapped.slice(mermaidMatch.index + mermaidMatch[0].length);\n const leadingLine = firstNonEmptyLine(before);\n const trailingLine = firstNonEmptyLine(after);\n\n if (!leadingLine || !trailingLine) {\n return unwrapped;\n }\n\n // Keep the essential nearby text around the mermaid block in wrapped payloads.\n return `${leadingLine}${mermaidMatch[0]}${trailingLine}`;\n};\n\nconst getFenceRanges = (raw: string): FenceRange[] => {\n const ranges: FenceRange[] = [];\n const fencePattern = /```/g;\n let match: RegExpExecArray | null;\n\n while ((match = fencePattern.exec(raw)) !== null) {\n const start = match.index;\n const closeMatch = fencePattern.exec(raw);\n if (!closeMatch) {\n ranges.push({ start, end: raw.length });\n break;\n }\n ranges.push({ start, end: closeMatch.index + 3 });\n }\n\n return ranges;\n};\n\nconst isIndexInRanges = (index: number, ranges: FenceRange[]) =>\n ranges.some(({ start, end }) => index >= start && index < end);\n\nconst findFirstMatchOutsideFence = (\n raw: string,\n pattern: RegExp,\n fenceRanges: FenceRange[]\n) => {\n const flags = pattern.flags.includes(\"g\")\n ? pattern.flags\n : `${pattern.flags}g`;\n const matcher = new RegExp(pattern.source, flags);\n let match: RegExpExecArray | null;\n\n while ((match = matcher.exec(raw)) !== null) {\n if (!isIndexInRanges(match.index, fenceRanges)) {\n return match.index;\n }\n }\n\n return -1;\n};\n\nconst findHtmlBlockEnd = (raw: string, startIndex: number) => {\n let blockEnd = raw.length;\n let match: RegExpExecArray | null;\n closingBoundary.lastIndex = 0;\n\n while ((match = closingBoundary.exec(raw))) {\n if (match.index <= startIndex) continue;\n blockEnd = match.index + match[0].length;\n break;\n }\n\n return blockEnd;\n};\n\nconst splitCustomButtonsFromSandbox = (segments: RenderSegment[]) => {\n if (!segments.length) return segments;\n const output: RenderSegment[] = [];\n\n segments.forEach((segment) => {\n if (segment.type !== \"sandbox\") {\n output.push(segment);\n return;\n }\n\n CUSTOM_BUTTON_PATTERN.lastIndex = 0;\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = CUSTOM_BUTTON_PATTERN.exec(segment.value)) !== null) {\n const before = segment.value.slice(lastIndex, match.index);\n if (before.trim()) {\n output.push({ type: \"sandbox\", value: before });\n }\n output.push({ type: \"markdown\", value: match[0] });\n lastIndex = match.index + match[0].length;\n }\n\n const rest = segment.value.slice(lastIndex);\n if (rest.trim()) {\n output.push({ type: \"sandbox\", value: rest });\n }\n });\n\n return output;\n};\n\nconst findInlineSandboxMatch = (raw: string): MatchResult | null => {\n let earliest: MatchResult | null = null;\n\n INLINE_SANDBOX_PATTERNS.forEach((pattern) => {\n const match = pattern.exec(raw);\n if (!match || typeof match.index !== \"number\") return;\n const start = match.index;\n const end = match.index + match[0].length;\n\n if (!earliest || start < earliest.start) {\n earliest = { start, end };\n }\n });\n\n return earliest;\n};\n\nconst pickEarliestMatch = (...matches: Array<MatchResult | null>) =>\n matches.reduce<MatchResult | null>((earliest, match) => {\n if (!match) return earliest;\n if (!earliest || match.start < earliest.start) return match;\n return earliest;\n }, null);\n\nconst findMarkdownImageMatch = (\n raw: string,\n fenceRanges: FenceRange[]\n): MatchResult | null => {\n const start = findFirstMatchOutsideFence(\n raw,\n MARKDOWN_IMAGE_PATTERN,\n fenceRanges\n );\n\n if (start === -1) return null;\n const match = raw.slice(start).match(MARKDOWN_IMAGE_PATTERN);\n if (!match) return null;\n\n return { start, end: start + match[0].length };\n};\n\nconst findMarkdownVideoIframeMatch = (\n raw: string,\n fenceRanges: FenceRange[]\n): MatchResult | null => {\n const start = findFirstMatchOutsideFence(\n raw,\n MARKDOWN_VIDEO_IFRAME_PATTERN,\n fenceRanges\n );\n\n if (start === -1) return null;\n const match = raw.slice(start).match(MARKDOWN_VIDEO_IFRAME_PATTERN);\n if (!match) return null;\n\n return { start, end: start + match[0].length };\n};\n\nconst isMarkdownVideoIframe = (value: string) =>\n MARKDOWN_VIDEO_IFRAME_PATTERN.test(value.trim());\n\nconst extractTableBlock = (\n raw: string\n): { start: number; block: string; end: number } | null => {\n const tableMatch = raw.match(/^\\s*\\|.+\\|\\s*$/m);\n if (!tableMatch || typeof tableMatch.index !== \"number\") return null;\n\n const leadingSpaces = tableMatch[0].match(/^\\s*/)?.[0].length ?? 0;\n const tableStart = tableMatch.index + leadingSpaces;\n\n const lines = raw.slice(tableStart).split(\"\\n\");\n const tableLines: string[] = [];\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith(\"|\")) break;\n tableLines.push(line);\n }\n\n const block = tableLines.join(\"\\n\");\n return { start: tableStart, block, end: tableStart + block.length };\n};\n\n// Split incoming markdown content into markdown and sandbox HTML segments\nexport const splitContentSegments = (\n raw: string,\n keepText = false\n): RenderSegment[] => {\n const source = normalizeQuotedMermaidContent(raw, keepText);\n const finalizeSegments = (segments: RenderSegment[]) =>\n splitCustomButtonsFromSandbox(segments);\n\n const fenceBlock = extractFirstFenceBlock(source);\n if (fenceBlock) {\n if (!fenceBlock.complete) {\n if (keepText) {\n return finalizeSegments([{ type: \"markdown\", value: source }]);\n }\n return finalizeSegments([{ type: \"markdown\", value: fenceBlock.block }]);\n }\n\n if (!keepText) {\n return finalizeSegments([{ type: \"markdown\", value: fenceBlock.block }]);\n }\n\n const segments: RenderSegment[] = [];\n const before = source.slice(0, fenceBlock.start);\n const normalizedBefore = normalizeBeforeFenceText(before);\n if (normalizedBefore.trim()) {\n segments.push({ type: \"text\", value: normalizedBefore });\n }\n\n segments.push({ type: \"markdown\", value: fenceBlock.block });\n\n const after = source.slice(fenceBlock.end);\n if (after.trim()) {\n segments.push(...splitContentSegments(after, true));\n }\n\n return finalizeSegments(segments);\n }\n\n const fenceRanges = getFenceRanges(source);\n // Avoid treating fenced code blocks as sandbox content.\n const sandboxStartIndex = findFirstMatchOutsideFence(\n source,\n SANDBOX_START_PATTERN,\n fenceRanges\n );\n const svgOpenIndex = findFirstMatchOutsideFence(\n source,\n /<svg\\b/i,\n fenceRanges\n );\n const hasSandboxBeforeSvg =\n sandboxStartIndex !== -1 &&\n svgOpenIndex !== -1 &&\n sandboxStartIndex < svgOpenIndex;\n const markdownImageBeforeSvg = findMarkdownImageMatch(source, fenceRanges);\n const hasMarkdownImageBeforeSvg =\n !!markdownImageBeforeSvg &&\n svgOpenIndex !== -1 &&\n markdownImageBeforeSvg.start < svgOpenIndex;\n if (\n svgOpenIndex !== -1 &&\n !hasSandboxBeforeSvg &&\n !hasMarkdownImageBeforeSvg\n ) {\n const before = source.slice(0, svgOpenIndex);\n const closeIdx = source.indexOf(\"</svg>\", svgOpenIndex);\n const svgBlock =\n closeIdx === -1\n ? `${source.slice(svgOpenIndex)}</svg>`\n : source.slice(svgOpenIndex, closeIdx + \"</svg>\".length);\n const after =\n closeIdx === -1 ? \"\" : source.slice(closeIdx + \"</svg>\".length);\n\n if (keepText) {\n const segments: RenderSegment[] = [];\n if (before.trim()) {\n segments.push({ type: \"text\", value: before });\n }\n segments.push({ type: \"markdown\", value: svgBlock });\n if (after.trim()) {\n segments.push(...splitContentSegments(after, true));\n }\n return finalizeSegments(segments);\n }\n\n if (closeIdx === -1) {\n return finalizeSegments([{ type: \"markdown\", value: svgBlock }]);\n }\n }\n\n const tableBlock = extractTableBlock(source);\n if (tableBlock) {\n const segments: RenderSegment[] = [];\n const before = source.slice(0, tableBlock.start);\n if (keepText && before.trim()) {\n segments.push(...splitContentSegments(before, true));\n }\n segments.push({ type: \"markdown\", value: tableBlock.block });\n const after = source.slice(tableBlock.end);\n const hasProgress = after.length < source.length;\n if (after.trim() && hasProgress) {\n segments.push(\n ...(keepText\n ? splitContentSegments(after, true)\n : splitContentSegments(after))\n );\n }\n return finalizeSegments(segments);\n }\n\n const inlineMatch = findInlineSandboxMatch(source);\n const markdownImageMatch = findMarkdownImageMatch(source, fenceRanges);\n const markdownVideoIframeMatch = findMarkdownVideoIframeMatch(\n source,\n fenceRanges\n );\n const inlineCandidate = pickEarliestMatch(\n inlineMatch,\n markdownImageMatch,\n markdownVideoIframeMatch\n );\n\n if (sandboxStartIndex === -1 && !inlineCandidate) {\n if (keepText && source.trim()) {\n return finalizeSegments([{ type: \"text\", value: source }]);\n }\n return [];\n }\n\n const shouldUseInline =\n !!inlineCandidate &&\n (sandboxStartIndex === -1 || inlineCandidate.start <= sandboxStartIndex);\n\n const startIndex = shouldUseInline\n ? inlineCandidate!.start\n : sandboxStartIndex;\n const blockEnd = shouldUseInline\n ? inlineCandidate!.end\n : findHtmlBlockEnd(source, startIndex);\n\n const segments: RenderSegment[] = [];\n const before = source.slice(0, startIndex);\n const matchedBlock = source.slice(startIndex, blockEnd);\n const isVideoIframeMatch =\n shouldUseInline && isMarkdownVideoIframe(matchedBlock);\n const normalizedBefore = isVideoIframeMatch ? before.trimEnd() : before;\n const after = source.slice(blockEnd);\n const normalizedAfter = isVideoIframeMatch ? after.trimStart() : after;\n\n if (keepText && normalizedBefore.trim()) {\n segments.push({ type: \"text\", value: normalizedBefore });\n }\n\n segments.push({\n type: shouldUseInline ? \"markdown\" : \"sandbox\",\n value: matchedBlock,\n });\n\n if (normalizedAfter.trim()) {\n segments.push(...splitContentSegments(normalizedAfter, keepText));\n }\n\n return finalizeSegments(segments);\n};\n"],"names":["SANDBOX_START_PATTERN","INLINE_SANDBOX_PATTERNS","MARKDOWN_IMAGE_PATTERN","MARKDOWN_VIDEO_IFRAME_PATTERN","closingBoundary","CUSTOM_BUTTON_PATTERN","WRAPPED_QUOTES_PATTERN","MERMAID_BLOCK_PATTERN","firstNonEmptyLine","content","line","extractFirstFenceBlock","raw","start","closing","normalizeBeforeFenceText","before","nonEmptyLines","normalizeQuotedMermaidContent","keepText","unwrapped","mermaidMatch","after","leadingLine","trailingLine","getFenceRanges","ranges","fencePattern","match","closeMatch","isIndexInRanges","index","end","findFirstMatchOutsideFence","pattern","fenceRanges","flags","matcher","findHtmlBlockEnd","startIndex","blockEnd","splitCustomButtonsFromSandbox","segments","output","segment","lastIndex","rest","findInlineSandboxMatch","earliest","pickEarliestMatch","matches","findMarkdownImageMatch","findMarkdownVideoIframeMatch","isMarkdownVideoIframe","value","extractTableBlock","tableMatch","leadingSpaces","tableStart","lines","tableLines","block","splitContentSegments","source","finalizeSegments","fenceBlock","normalizedBefore","sandboxStartIndex","svgOpenIndex","hasSandboxBeforeSvg","markdownImageBeforeSvg","hasMarkdownImageBeforeSvg","closeIdx","svgBlock","tableBlock","hasProgress","inlineMatch","markdownImageMatch","markdownVideoIframeMatch","inlineCandidate","shouldUseInline","matchedBlock","isVideoIframeMatch","normalizedAfter"],"mappings":"AAKA,MAAMA,IACJ,sGAEIC,IAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACMC,IAAyB,2CACzBC,IACJ,yEAEIC,IAAkB,mCAClBC,IACJ,2EAQIC,IAAyB,eACzBC,IAAwB,0BAExBC,IAAoB,CAACC,MACzBA,EACG,MAAM,OAAO,EACb,IAAI,CAACC,MAASA,EAAK,KAAA,CAAM,EACzB,KAAK,OAAO,KAAK,IAEhBC,IAAyB,CAACC,MAAmC;AACjE,QAAMC,IAAQD,EAAI,QAAQ,KAAK;AAC/B,MAAIC,MAAU,GAAI,QAAO;AAEzB,QAAMC,IAAUF,EAAI,QAAQ,OAAOC,IAAQ,CAAC;AAC5C,SAAIC,MAAY,KACP;AAAA,IACL,OAAAD;AAAA,IACA,OAAOD,EAAI,MAAMC,CAAK;AAAA,IACtB,UAAU;AAAA,EAAA,IAIP;AAAA,IACL,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S+C,EAAO,MAAM,GAAGxB,CAAU,GACnC0C,IAAelB,EAAO,MAAMxB,GAAYC,CAAQ,GAChD0C,IACJF,KAAmB3B,EAAsB4B,CAAY,GACjDf,IAAmBgB,IAAqBlE,EAAO,QAAA,IAAYA,GAC3DM,IAAQyC,EAAO,MAAMvB,CAAQ,GAC7B2C,IAAkBD,IAAqB5D,EAAM,UAAA,IAAcA;AAEjE,SAAIH,KAAY+C,EAAiB,UAC/BxB,EAAS,KAAK,EAAE,MAAM,QAAQ,OAAOwB,GAAkB,GAGzDxB,EAAS,KAAK;AAAA,IACZ,MAAMsC,IAAkB,aAAa;AAAA,IACrC,OAAOC;AAAA,EAAA,CACR,GAEGE,EAAgB,UAClBzC,EAAS,KAAK,GAAGoB,EAAqBqB,GAAiBhE,CAAQ,CAAC,GAG3D6C,EAAiBtB,CAAQ;AAClC;"}
1
+ {"version":3,"file":"split-content.es.js","sources":["../../../../src/components/ContentRender/utils/split-content.ts"],"sourcesContent":["export type RenderSegment =\n | { type: \"markdown\"; value: string }\n | { type: \"sandbox\"; value: string }\n | { type: \"text\"; value: string };\n\nconst SANDBOX_START_PATTERN =\n /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\\s>]/i;\n\nconst INLINE_SANDBOX_PATTERNS: RegExp[] = [\n /<svg[\\s\\S]*?<\\/svg>/i,\n /<img\\b[^>]*?>/i,\n /```mermaid[\\s\\S]*?```/i,\n /```[a-zA-Z0-9]+[\\s\\S]*?```/i,\n];\nconst MARKDOWN_IMAGE_PATTERN = /!\\[[^\\]]*]\\([^\\s)\\n]+(?:\\s+\"[^\"]*\")?\\)/i;\nconst MARKDOWN_VIDEO_IFRAME_PATTERN =\n /<iframe\\b[^>]*\\bdata-tag\\s*=\\s*([\"'])video\\1[^>]*>[\\s\\S]*?<\\/iframe>/i;\nconst DIFF_BLOCK_START_PATTERN = /!\\+\\+\\+/i;\n\nconst closingBoundary = /<\\/[a-z][^>]*>\\s*\\n(?=[^\\s<])/gi;\nconst CUSTOM_BUTTON_PATTERN =\n /<custom-button-after-content\\b[\\s\\S]*?<\\/custom-button-after-content>/gi;\n\ntype MatchResult = { start: number; end: number };\ntype FenceRange = { start: number; end: number };\ntype FenceBlock =\n | { start: number; end: number; block: string; complete: true }\n | { start: number; block: string; complete: false };\n\nconst WRAPPED_QUOTES_PATTERN = /^\"[\\s\\S]*\"$/;\nconst MERMAID_BLOCK_PATTERN = /```mermaid[\\s\\S]*?```/i;\n\nconst firstNonEmptyLine = (content: string) =>\n content\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .find(Boolean) ?? \"\";\n\nconst extractFirstFenceBlock = (raw: string): FenceBlock | null => {\n const start = raw.indexOf(\"```\");\n if (start === -1) return null;\n\n const closing = raw.indexOf(\"```\", start + 3);\n if (closing === -1) {\n return {\n start,\n block: raw.slice(start),\n complete: false,\n };\n }\n\n return {\n start,\n end: closing + 3,\n block: raw.slice(start, closing + 3),\n complete: true,\n };\n};\n\nconst normalizeBeforeFenceText = (before: string) => {\n const nonEmptyLines = before\n .split(/\\r?\\n/)\n .map((line) => line.trim())\n .filter(Boolean);\n\n if (nonEmptyLines.length <= 1) return before;\n return nonEmptyLines[0];\n};\n\nconst normalizeQuotedMermaidContent = (raw: string, keepText: boolean) => {\n if (!WRAPPED_QUOTES_PATTERN.test(raw)) return raw;\n\n const unwrapped = raw.slice(1, -1);\n if (!keepText) return unwrapped;\n\n const mermaidMatch = unwrapped.match(MERMAID_BLOCK_PATTERN);\n if (!mermaidMatch || typeof mermaidMatch.index !== \"number\") {\n return unwrapped;\n }\n\n const before = unwrapped.slice(0, mermaidMatch.index);\n const after = unwrapped.slice(mermaidMatch.index + mermaidMatch[0].length);\n const leadingLine = firstNonEmptyLine(before);\n const trailingLine = firstNonEmptyLine(after);\n\n if (!leadingLine || !trailingLine) {\n return unwrapped;\n }\n\n // Keep the essential nearby text around the mermaid block in wrapped payloads.\n return `${leadingLine}${mermaidMatch[0]}${trailingLine}`;\n};\n\nconst getFenceRanges = (raw: string): FenceRange[] => {\n const ranges: FenceRange[] = [];\n const fencePattern = /```/g;\n let match: RegExpExecArray | null;\n\n while ((match = fencePattern.exec(raw)) !== null) {\n const start = match.index;\n const closeMatch = fencePattern.exec(raw);\n if (!closeMatch) {\n ranges.push({ start, end: raw.length });\n break;\n }\n ranges.push({ start, end: closeMatch.index + 3 });\n }\n\n return ranges;\n};\n\nconst isIndexInRanges = (index: number, ranges: FenceRange[]) =>\n ranges.some(({ start, end }) => index >= start && index < end);\n\nconst findFirstMatchOutsideFence = (\n raw: string,\n pattern: RegExp,\n fenceRanges: FenceRange[]\n) => {\n const flags = pattern.flags.includes(\"g\")\n ? pattern.flags\n : `${pattern.flags}g`;\n const matcher = new RegExp(pattern.source, flags);\n let match: RegExpExecArray | null;\n\n while ((match = matcher.exec(raw)) !== null) {\n if (!isIndexInRanges(match.index, fenceRanges)) {\n return match.index;\n }\n }\n\n return -1;\n};\n\nconst findHtmlBlockEnd = (raw: string, startIndex: number) => {\n let blockEnd = raw.length;\n let match: RegExpExecArray | null;\n closingBoundary.lastIndex = 0;\n\n while ((match = closingBoundary.exec(raw))) {\n if (match.index <= startIndex) continue;\n blockEnd = match.index + match[0].length;\n break;\n }\n\n return blockEnd;\n};\n\nconst splitCustomButtonsFromSandbox = (segments: RenderSegment[]) => {\n if (!segments.length) return segments;\n const output: RenderSegment[] = [];\n\n segments.forEach((segment) => {\n if (segment.type !== \"sandbox\") {\n output.push(segment);\n return;\n }\n\n CUSTOM_BUTTON_PATTERN.lastIndex = 0;\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n\n while ((match = CUSTOM_BUTTON_PATTERN.exec(segment.value)) !== null) {\n const before = segment.value.slice(lastIndex, match.index);\n if (before.trim()) {\n output.push({ type: \"sandbox\", value: before });\n }\n output.push({ type: \"markdown\", value: match[0] });\n lastIndex = match.index + match[0].length;\n }\n\n const rest = segment.value.slice(lastIndex);\n if (rest.trim()) {\n output.push({ type: \"sandbox\", value: rest });\n }\n });\n\n return output;\n};\n\nconst findInlineSandboxMatch = (raw: string): MatchResult | null => {\n let earliest: MatchResult | null = null;\n\n INLINE_SANDBOX_PATTERNS.forEach((pattern) => {\n const match = pattern.exec(raw);\n if (!match || typeof match.index !== \"number\") return;\n const start = match.index;\n const end = match.index + match[0].length;\n\n if (!earliest || start < earliest.start) {\n earliest = { start, end };\n }\n });\n\n return earliest;\n};\n\nconst pickEarliestMatch = (...matches: Array<MatchResult | null>) =>\n matches.reduce<MatchResult | null>((earliest, match) => {\n if (!match) return earliest;\n if (!earliest || match.start < earliest.start) return match;\n return earliest;\n }, null);\n\nconst findMarkdownImageMatch = (\n raw: string,\n fenceRanges: FenceRange[]\n): MatchResult | null => {\n const start = findFirstMatchOutsideFence(\n raw,\n MARKDOWN_IMAGE_PATTERN,\n fenceRanges\n );\n\n if (start === -1) return null;\n const match = raw.slice(start).match(MARKDOWN_IMAGE_PATTERN);\n if (!match) return null;\n\n return { start, end: start + match[0].length };\n};\n\nconst findMarkdownVideoIframeMatch = (\n raw: string,\n fenceRanges: FenceRange[]\n): MatchResult | null => {\n const start = findFirstMatchOutsideFence(\n raw,\n MARKDOWN_VIDEO_IFRAME_PATTERN,\n fenceRanges\n );\n\n if (start === -1) return null;\n const match = raw.slice(start).match(MARKDOWN_VIDEO_IFRAME_PATTERN);\n if (!match) return null;\n\n return { start, end: start + match[0].length };\n};\n\nconst findDiffSandboxMatch = (\n raw: string,\n fenceRanges: FenceRange[]\n): MatchResult | null => {\n const start = findFirstMatchOutsideFence(\n raw,\n DIFF_BLOCK_START_PATTERN,\n fenceRanges\n );\n if (start === -1) return null;\n\n const closeIndex = raw.indexOf(\"!+++\", start + 4);\n const end = closeIndex === -1 ? raw.length : closeIndex + 4;\n return { start, end };\n};\n\nconst isMarkdownVideoIframe = (value: string) =>\n MARKDOWN_VIDEO_IFRAME_PATTERN.test(value.trim());\n\nconst extractTableBlock = (\n raw: string\n): { start: number; block: string; end: number } | null => {\n const tableMatch = raw.match(/^\\s*\\|.+\\|\\s*$/m);\n if (!tableMatch || typeof tableMatch.index !== \"number\") return null;\n\n const leadingSpaces = tableMatch[0].match(/^\\s*/)?.[0].length ?? 0;\n const tableStart = tableMatch.index + leadingSpaces;\n\n const lines = raw.slice(tableStart).split(\"\\n\");\n const tableLines: string[] = [];\n\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith(\"|\")) break;\n tableLines.push(line);\n }\n\n const block = tableLines.join(\"\\n\");\n return { start: tableStart, block, end: tableStart + block.length };\n};\n\n// Split incoming markdown content into markdown and sandbox HTML segments\nexport const splitContentSegments = (\n raw: string,\n keepText = false\n): RenderSegment[] => {\n const source = normalizeQuotedMermaidContent(raw, keepText);\n const finalizeSegments = (segments: RenderSegment[]) =>\n splitCustomButtonsFromSandbox(segments);\n\n const fenceBlock = extractFirstFenceBlock(source);\n if (fenceBlock) {\n if (!fenceBlock.complete) {\n if (keepText) {\n return finalizeSegments([{ type: \"markdown\", value: source }]);\n }\n return finalizeSegments([{ type: \"markdown\", value: fenceBlock.block }]);\n }\n\n if (!keepText) {\n return finalizeSegments([{ type: \"markdown\", value: fenceBlock.block }]);\n }\n\n const segments: RenderSegment[] = [];\n const before = source.slice(0, fenceBlock.start);\n const normalizedBefore = normalizeBeforeFenceText(before);\n if (normalizedBefore.trim()) {\n segments.push({ type: \"text\", value: normalizedBefore });\n }\n\n segments.push({ type: \"markdown\", value: fenceBlock.block });\n\n const after = source.slice(fenceBlock.end);\n if (after.trim()) {\n segments.push(...splitContentSegments(after, true));\n }\n\n return finalizeSegments(segments);\n }\n\n const fenceRanges = getFenceRanges(source);\n // Avoid treating fenced code blocks as sandbox content.\n const sandboxStartIndex = findFirstMatchOutsideFence(\n source,\n SANDBOX_START_PATTERN,\n fenceRanges\n );\n const svgOpenIndex = findFirstMatchOutsideFence(\n source,\n /<svg\\b/i,\n fenceRanges\n );\n const hasSandboxBeforeSvg =\n sandboxStartIndex !== -1 &&\n svgOpenIndex !== -1 &&\n sandboxStartIndex < svgOpenIndex;\n const markdownImageBeforeSvg = findMarkdownImageMatch(source, fenceRanges);\n const hasMarkdownImageBeforeSvg =\n !!markdownImageBeforeSvg &&\n svgOpenIndex !== -1 &&\n markdownImageBeforeSvg.start < svgOpenIndex;\n if (\n svgOpenIndex !== -1 &&\n !hasSandboxBeforeSvg &&\n !hasMarkdownImageBeforeSvg\n ) {\n const before = source.slice(0, svgOpenIndex);\n const closeIdx = source.indexOf(\"</svg>\", svgOpenIndex);\n const svgBlock =\n closeIdx === -1\n ? `${source.slice(svgOpenIndex)}</svg>`\n : source.slice(svgOpenIndex, closeIdx + \"</svg>\".length);\n const after =\n closeIdx === -1 ? \"\" : source.slice(closeIdx + \"</svg>\".length);\n\n if (keepText) {\n const segments: RenderSegment[] = [];\n if (before.trim()) {\n segments.push({ type: \"text\", value: before });\n }\n segments.push({ type: \"markdown\", value: svgBlock });\n if (after.trim()) {\n segments.push(...splitContentSegments(after, true));\n }\n return finalizeSegments(segments);\n }\n\n if (closeIdx === -1) {\n return finalizeSegments([{ type: \"markdown\", value: svgBlock }]);\n }\n }\n\n const tableBlock = extractTableBlock(source);\n if (tableBlock) {\n const segments: RenderSegment[] = [];\n const before = source.slice(0, tableBlock.start);\n if (keepText && before.trim()) {\n segments.push(...splitContentSegments(before, true));\n }\n segments.push({ type: \"markdown\", value: tableBlock.block });\n const after = source.slice(tableBlock.end);\n const hasProgress = after.length < source.length;\n if (after.trim() && hasProgress) {\n segments.push(\n ...(keepText\n ? splitContentSegments(after, true)\n : splitContentSegments(after))\n );\n }\n return finalizeSegments(segments);\n }\n\n const inlineMatch = findInlineSandboxMatch(source);\n const markdownImageMatch = findMarkdownImageMatch(source, fenceRanges);\n const markdownVideoIframeMatch = findMarkdownVideoIframeMatch(\n source,\n fenceRanges\n );\n const diffSandboxMatch = findDiffSandboxMatch(source, fenceRanges);\n const inlineCandidate = pickEarliestMatch(\n inlineMatch,\n markdownImageMatch,\n markdownVideoIframeMatch\n );\n\n if (sandboxStartIndex === -1 && !inlineCandidate && !diffSandboxMatch) {\n if (keepText && source.trim()) {\n return finalizeSegments([{ type: \"text\", value: source }]);\n }\n return [];\n }\n\n const shouldUseInline =\n !!inlineCandidate &&\n (sandboxStartIndex === -1 || inlineCandidate.start <= sandboxStartIndex);\n\n const shouldUseDiffSandbox =\n !!diffSandboxMatch &&\n (sandboxStartIndex === -1 || diffSandboxMatch.start <= sandboxStartIndex) &&\n (!inlineCandidate || diffSandboxMatch.start <= inlineCandidate.start);\n\n const startIndex = shouldUseDiffSandbox\n ? diffSandboxMatch.start\n : shouldUseInline\n ? inlineCandidate!.start\n : sandboxStartIndex;\n const blockEnd = shouldUseDiffSandbox\n ? diffSandboxMatch.end\n : shouldUseInline\n ? inlineCandidate!.end\n : findHtmlBlockEnd(source, startIndex);\n\n const segments: RenderSegment[] = [];\n const before = source.slice(0, startIndex);\n const matchedBlock = source.slice(startIndex, blockEnd);\n const isVideoIframeMatch =\n shouldUseInline && isMarkdownVideoIframe(matchedBlock);\n const normalizedBefore = isVideoIframeMatch ? before.trimEnd() : before;\n const after = source.slice(blockEnd);\n const normalizedAfter = isVideoIframeMatch ? after.trimStart() : after;\n\n if (keepText && normalizedBefore.trim()) {\n segments.push({ type: \"text\", value: normalizedBefore });\n }\n\n segments.push({\n type: shouldUseInline ? \"markdown\" : \"sandbox\",\n value: matchedBlock,\n });\n\n if (normalizedAfter.trim()) {\n segments.push(...splitContentSegments(normalizedAfter, keepText));\n }\n\n return finalizeSegments(segments);\n};\n"],"names":["SANDBOX_START_PATTERN","INLINE_SANDBOX_PATTERNS","MARKDOWN_IMAGE_PATTERN","MARKDOWN_VIDEO_IFRAME_PATTERN","DIFF_BLOCK_START_PATTERN","closingBoundary","CUSTOM_BUTTON_PATTERN","WRAPPED_QUOTES_PATTERN","MERMAID_BLOCK_PATTERN","firstNonEmptyLine","content","line","extractFirstFenceBlock","raw","start","closing","normalizeBeforeFenceText","before","nonEmptyLines","normalizeQuotedMermaidContent","keepText","unwrapped","mermaidMatch","after","leadingLine","trailingLine","getFenceRanges","ranges","fencePattern","match","closeMatch","isIndexInRanges","index","end","findFirstMatchOutsideFence","pattern","fenceRanges","flags","matcher","findHtmlBlockEnd","startIndex","blockEnd","splitCustomButtonsFromSandbox","segments","output","segment","lastIndex","rest","findInlineSandboxMatch","earliest","pickEarliestMatch","matches","findMarkdownImageMatch","findMarkdownVideoIframeMatch","findDiffSandboxMatch","closeIndex","isMarkdownVideoIframe","value","extractTableBlock","tableMatch","leadingSpaces","tableStart","lines","tableLines","block","splitContentSegments","source","finalizeSegments","fenceBlock","normalizedBefore","sandboxStartIndex","svgOpenIndex","hasSandboxBeforeSvg","markdownImageBeforeSvg","hasMarkdownImageBeforeSvg","closeIdx","svgBlock","tableBlock","hasProgress","inlineMatch","markdownImageMatch","markdownVideoIframeMatch","diffSandboxMatch","inlineCandidate","shouldUseInline","shouldUseDiffSandbox","matchedBlock","isVideoIframeMatch","normalizedAfter"],"mappings":"AAKA,MAAMA,IACJ,sGAEIC,IAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACMC,IAAyB,2CACzBC,IACJ,yEACIC,IAA2B,YAE3BC,IAAkB,mCAClBC,IACJ,2EAQIC,IAAyB,eACzBC,IAAwB,0BAExBC,IAAoB,CAACC,MACzBA,EACG,MAAM,OAAO,EACb,IAAI,CAACC,MAASA,EAAK,KAAA,CAAM,EACzB,KAAK,OAAO,KAAK,IAEhBC,IAAyB,CAACC,MAAmC;AACjE,QAAMC,IAAQD,EAAI,QAAQ,KAAK;AAC/B,MAAIC,MAAU,GAAI,QAAO;AAEzB,QAAMC,IAAUF,EAAI,QAAQ,OAAOC,IAAQ,CAAC;AAC5C,SAAIC,MAAY,KACP;AAAA,IACL,OAAAD;AAAA,IACA,OAAOD,EAAI,MAAMC,CAAK;AAAA,IACtB,UAAU;AAAA,EAAA,IAIP;AAAA,IACL,OAAAA;AAAA,IACA,KAAKC,IAAU;AAAA,IACf,OA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