markdown-flow-ui 0.1.83-beta.1 → 0.1.83-beta.11

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.
@@ -1,77 +1,69 @@
1
- import { j as u } from "../../_virtual/jsx-runtime.js";
2
- import { useRef as n, useState as b, useEffect as v } from "react";
3
- import Y from "../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.js";
4
- const re = ({
5
- html: f,
6
- loadingText: q,
7
- styleLoadingText: B,
8
- scriptLoadingText: H,
9
- fullScreenButtonText: L,
10
- resetToken: p = 0
1
+ import { j as v } from "../../_virtual/jsx-runtime.js";
2
+ import { useRef as n, useState as A, useEffect as I } from "react";
3
+ import K from "../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.js";
4
+ const Z = ({
5
+ html: u,
6
+ loadingText: B,
7
+ styleLoadingText: W,
8
+ scriptLoadingText: z,
9
+ resetToken: f = 0
11
10
  }) => {
12
- const A = n(null), S = n(null), [k, N] = b(!0), [V, C] = b(!1), [_, w] = b(!1), [O, Q] = b(!1), R = n([]), F = n([]), j = n(0), M = n(0), d = n(null), m = n(null), h = n(!1), y = n(!1), I = n(!1), D = n(p), J = 200, o = (e) => {
13
- e.current && (clearTimeout(e.current), e.current = null);
14
- }, T = (e, s, c, x) => {
15
- const a = performance.now() - c.current, E = Math.max(0, J - a);
16
- o(s), s.current = window.setTimeout(() => {
17
- e(!1), x?.(), s.current = null;
18
- }, E);
11
+ const q = n(null), S = n(null), [H, L] = A(!0), [V, C] = A(!1), [_, E] = A(!1), b = n([]), w = n([]), N = n(0), j = n(0), p = n(null), d = n(null), m = n(!1), h = n(!1), R = n(!1), D = n(f), O = 200, c = (t) => {
12
+ t.current && (clearTimeout(t.current), t.current = null);
13
+ }, M = (t, s, o, g) => {
14
+ const a = performance.now() - o.current, x = Math.max(0, O - a);
15
+ c(s), s.current = window.setTimeout(() => {
16
+ t(!1), g?.(), s.current = null;
17
+ }, x);
19
18
  };
20
- v(() => {
21
- const e = () => {
22
- Q(!!document.fullscreenElement);
23
- };
24
- return document.addEventListener("fullscreenchange", e), () => {
25
- document.removeEventListener("fullscreenchange", e);
26
- };
27
- }, []), v(() => {
28
- const e = S.current?.ownerDocument;
29
- if (!e) return;
19
+ I(() => {
20
+ const t = S.current?.ownerDocument;
21
+ if (!t) return;
30
22
  const s = "sandbox-spinner-style";
31
- let c = e.getElementById(s);
32
- c || (c = e.createElement("style"), c.id = s, c.textContent = "@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }", e.head?.appendChild(c));
33
- }, []), v(() => {
34
- p !== D.current && (I.current = !1, D.current = p), o(d), o(m), h.current = !1, y.current = !1;
35
- const e = S.current;
36
- if (!e) return;
37
- const s = e.ownerDocument, c = s?.body;
38
- if (!c) return;
39
- R.current.forEach((t) => t.remove()), R.current = [], F.current.forEach((t) => t.remove()), F.current = [];
40
- const x = I.current;
41
- N(!x), C(!1), w(!1), e.innerHTML = "";
23
+ let o = t.getElementById(s);
24
+ o || (o = t.createElement("style"), o.id = s, o.textContent = "@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }", t.head?.appendChild(o));
25
+ }, []), I(() => {
26
+ f !== D.current && (R.current = !1, D.current = f), c(p), c(d), m.current = !1, h.current = !1;
27
+ const t = S.current;
28
+ if (!t) return;
29
+ const s = t.ownerDocument, o = s?.body;
30
+ if (!o) return;
31
+ b.current.forEach((e) => e.remove()), b.current = [], w.current.forEach((e) => e.remove()), w.current = [];
32
+ const g = R.current;
33
+ L(!g), C(!1), E(!1), t.innerHTML = "";
42
34
  const a = document.createElement("div");
43
- a.innerHTML = f;
44
- const E = (f.match(/<script[\s>]/gi) || []).length, P = (f.match(/<\/script>/gi) || []).length, U = E > 0 && E === P, l = [];
45
- Array.from(a.querySelectorAll("style, script")).forEach((t) => {
46
- if (t.tagName.toLowerCase() === "style") {
35
+ a.innerHTML = u;
36
+ const x = (u.match(/<script[\s>]/gi) || []).length, Q = (u.match(/<\/script>/gi) || []).length, k = x > 0 && x === Q, l = [];
37
+ Array.from(a.querySelectorAll("style, script")).forEach((e) => {
38
+ if (e.tagName.toLowerCase() === "style") {
47
39
  const r = s.createElement("style");
48
- r.textContent = t.textContent || "", Array.from(t.attributes).forEach((i) => {
40
+ r.textContent = e.textContent || "", Array.from(e.attributes).forEach((i) => {
49
41
  r.setAttribute(i.name, i.value);
50
42
  }), l.push(r);
51
43
  } else {
52
44
  const r = s.createElement("script");
53
- Array.from(t.attributes).forEach((i) => {
45
+ Array.from(e.attributes).forEach((i) => {
54
46
  r.setAttribute(i.name, i.value);
55
- }), r.textContent = t.textContent || "", l.push(r);
47
+ }), r.textContent = e.textContent || "", l.push(r);
56
48
  }
57
- t.remove();
49
+ e.remove();
58
50
  });
59
- const z = l.some(
60
- (t) => t.tagName.toLowerCase() === "style"
61
- ), G = l.some(
62
- (t) => t.tagName.toLowerCase() === "script"
51
+ const T = l.some(
52
+ (e) => e.tagName.toLowerCase() === "style"
53
+ ), F = l.some(
54
+ (e) => e.tagName.toLowerCase() === "script"
63
55
  );
64
- z && (h.current = !0, j.current = performance.now(), o(d), C(!0)), G && (y.current = !0, M.current = performance.now(), o(m), w(!0));
65
- const W = !!a.firstElementChild;
66
- N(!W && !x), W && (I.current = !0);
67
- const X = Array.from(a.childNodes);
68
- e.append(...X), l.forEach((t) => {
69
- if (t.tagName.toLowerCase() === "style") {
70
- s.head?.appendChild(t), R.current.push(t);
56
+ T && (m.current = !0, N.current = performance.now(), c(p), C(!0)), F && (h.current = !0, j.current = performance.now(), c(d), E(!0));
57
+ const G = !!a.firstElementChild;
58
+ L(!G && !g), G && (R.current = !0);
59
+ const J = Array.from(a.childNodes);
60
+ t.append(...J), l.forEach((e) => {
61
+ if (e.tagName.toLowerCase() === "style") {
62
+ s.head?.appendChild(e), b.current.push(e);
71
63
  return;
72
64
  }
73
- if (U) {
74
- const r = t, i = r.textContent || "";
65
+ if (k) {
66
+ const r = e, i = r.textContent || "";
75
67
  if (!r.src)
76
68
  try {
77
69
  new Function(i);
@@ -80,86 +72,59 @@ const re = ({
80
72
  return;
81
73
  }
82
74
  try {
83
- c.appendChild(r), F.current.push(r);
75
+ o.appendChild(r), w.current.push(r);
84
76
  } catch {
85
77
  r.remove();
86
78
  }
87
79
  } else
88
- t.remove();
80
+ e.remove();
89
81
  }), requestAnimationFrame(() => {
90
- z && T(
82
+ T && M(
91
83
  C,
84
+ p,
85
+ N,
86
+ () => {
87
+ m.current = !1;
88
+ }
89
+ ), F && M(
90
+ E,
92
91
  d,
93
92
  j,
94
93
  () => {
95
94
  h.current = !1;
96
95
  }
97
- ), G && T(
98
- w,
99
- m,
100
- M,
101
- () => {
102
- y.current = !1;
103
- }
104
96
  );
105
97
  });
106
- }, [f, p]), v(
98
+ }, [u, f]), I(
107
99
  () => () => {
108
- o(d), o(m);
100
+ c(p), c(d);
109
101
  },
110
102
  []
111
103
  );
112
- const g = _ || y.current ? H || "Building scripts cache..." : V || h.current ? B || "Building styles..." : k ? q || "Loading..." : null, K = () => {
113
- const e = A.current;
114
- if (e) {
115
- if (!document.fullscreenElement) {
116
- e.requestFullscreen?.().catch(() => {
117
- });
118
- return;
119
- }
120
- document.exitFullscreen?.();
121
- }
122
- };
123
- return /* @__PURE__ */ u.jsxs(
104
+ const y = _ || h.current ? z || "Building scripts cache..." : V || m.current ? W || "Building styles..." : H ? B || "Loading..." : null;
105
+ return /* @__PURE__ */ v.jsxs(
124
106
  "div",
125
107
  {
126
- ref: A,
127
- style: { position: "relative", minHeight: 120 },
128
- "aria-busy": !!g,
108
+ ref: q,
109
+ style: {
110
+ position: "relative",
111
+ height: "100vh",
112
+ display: "flex",
113
+ flexDirection: "column",
114
+ justifyContent: "center"
115
+ },
116
+ "aria-busy": !!y,
129
117
  children: [
130
- /* @__PURE__ */ u.jsx(
118
+ /* @__PURE__ */ v.jsx(
131
119
  "div",
132
120
  {
133
121
  ref: S,
134
122
  style: {
135
- pointerEvents: g ? "none" : void 0
123
+ pointerEvents: y ? "none" : void 0
136
124
  }
137
125
  }
138
126
  ),
139
- /* @__PURE__ */ u.jsx(
140
- "button",
141
- {
142
- type: "button",
143
- onClick: K,
144
- style: {
145
- position: "absolute",
146
- top: 8,
147
- right: 8,
148
- zIndex: 30,
149
- padding: "6px 10px",
150
- borderRadius: 6,
151
- border: "1px solid #cbd5e1",
152
- background: "#ffffffcc",
153
- color: "#0f172a",
154
- fontSize: 12,
155
- fontWeight: 600,
156
- cursor: "pointer",
157
- boxShadow: "0 4px 10px rgba(15, 23, 42, 0.08)"
158
- },
159
- children: O ? L || "Exit Fullscreen" : L || "Fullscreen"
160
- }
161
- ),
162
- g && /* @__PURE__ */ u.jsxs(
127
+ y && /* @__PURE__ */ v.jsxs(
163
128
  "div",
164
129
  {
165
130
  style: {
@@ -177,15 +142,15 @@ const re = ({
177
142
  zIndex: 20
178
143
  },
179
144
  children: [
180
- /* @__PURE__ */ u.jsx(
181
- Y,
145
+ /* @__PURE__ */ v.jsx(
146
+ K,
182
147
  {
183
148
  "aria-hidden": !0,
184
149
  size: 20,
185
150
  style: { animation: "sandbox-spin 1s linear infinite" }
186
151
  }
187
152
  ),
188
- g
153
+ y
189
154
  ]
190
155
  }
191
156
  )
@@ -194,6 +159,6 @@ const re = ({
194
159
  );
195
160
  };
196
161
  export {
197
- re as default
162
+ Z as default
198
163
  };
199
164
  //# sourceMappingURL=SandboxApp.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"SandboxApp.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { Loader2 } from \"lucide-react\";\n\nexport interface SandboxAppProps {\n html: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n resetToken?: number;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n resetToken = 0,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [isWaitingFirstDiv, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = useState(false);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const appendedStylesRef = useRef<HTMLStyleElement[]>([]);\n const appendedScriptsRef = useRef<HTMLScriptElement[]>([]);\n const styleStartRef = useRef(0);\n const scriptStartRef = useRef(0);\n const styleTimerRef = useRef<number | null>(null);\n const scriptTimerRef = useRef<number | null>(null);\n const hasStylesRef = useRef(false);\n const hasScriptsRef = useRef(false);\n const hasRenderedContentRef = useRef(false);\n const prevResetTokenRef = useRef(resetToken);\n const MIN_LOADING_MS = 200;\n\n const clearTimer = (timerRef: React.MutableRefObject<number | null>) => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n };\n\n const settleStateWithMinimumDelay = (\n setter: React.Dispatch<React.SetStateAction<boolean>>,\n timerRef: React.MutableRefObject<number | null>,\n startRef: React.MutableRefObject<number>,\n onDone?: () => void\n ) => {\n const elapsed = performance.now() - startRef.current;\n const delay = Math.max(0, MIN_LOADING_MS - elapsed);\n clearTimer(timerRef);\n timerRef.current = window.setTimeout(() => {\n setter(false);\n onDone?.();\n timerRef.current = null;\n }, delay);\n };\n\n useEffect(() => {\n const onFullscreenChange = () => {\n setIsFullscreen(!!document.fullscreenElement);\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () => {\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n };\n }, []);\n\n useEffect(() => {\n const doc = containerRef.current?.ownerDocument;\n if (!doc) return;\n const styleId = \"sandbox-spinner-style\";\n let styleEl = doc.getElementById(styleId) as HTMLStyleElement | null;\n if (!styleEl) {\n styleEl = doc.createElement(\"style\");\n styleEl.id = styleId;\n styleEl.textContent =\n \"@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\";\n doc.head?.appendChild(styleEl);\n }\n }, []);\n\n useEffect(() => {\n if (resetToken !== prevResetTokenRef.current) {\n hasRenderedContentRef.current = false;\n prevResetTokenRef.current = resetToken;\n }\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n\n const container = containerRef.current;\n if (!container) return;\n const doc = container.ownerDocument;\n const body = doc?.body;\n if (!body) return;\n\n appendedStylesRef.current.forEach((node) => node.remove());\n appendedStylesRef.current = [];\n appendedScriptsRef.current.forEach((node) => node.remove());\n appendedScriptsRef.current = [];\n\n const hasRenderedBefore = hasRenderedContentRef.current;\n setIsWaitingFirstDiv(!hasRenderedBefore);\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n container.innerHTML = \"\";\n const wrapper = document.createElement(\"div\");\n wrapper.innerHTML = html;\n\n const openScriptCount = (html.match(/<script[\\s>]/gi) || []).length;\n const closeScriptCount = (html.match(/<\\/script>/gi) || []).length;\n const shouldExecuteScripts =\n openScriptCount > 0 && openScriptCount === closeScriptCount;\n\n const resourceQueue: HTMLElement[] = [];\n\n Array.from(wrapper.querySelectorAll(\"style, script\")).forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n const cloned = doc.createElement(\"style\");\n cloned.textContent = node.textContent || \"\";\n Array.from(node.attributes).forEach((attr) => {\n cloned.setAttribute(attr.name, attr.value);\n });\n resourceQueue.push(cloned);\n } else {\n const replacement = doc.createElement(\"script\");\n Array.from(node.attributes).forEach((attr) => {\n replacement.setAttribute(attr.name, attr.value);\n });\n replacement.textContent = node.textContent || \"\";\n resourceQueue.push(replacement);\n }\n node.remove();\n });\n\n const hasStyles = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"style\"\n );\n const hasScripts = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"script\"\n );\n if (hasStyles) {\n hasStylesRef.current = true;\n styleStartRef.current = performance.now();\n clearTimer(styleTimerRef);\n setIsGeneratingStyles(true);\n }\n if (hasScripts) {\n hasScriptsRef.current = true;\n scriptStartRef.current = performance.now();\n clearTimer(scriptTimerRef);\n setIsGeneratingScripts(true);\n }\n\n const hasFirstElement = !!wrapper.firstElementChild;\n setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.append(...contentNodes);\n\n resourceQueue.forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n doc.head?.appendChild(node);\n appendedStylesRef.current.push(node as HTMLStyleElement);\n return;\n }\n\n if (shouldExecuteScripts) {\n const scriptNode = node as HTMLScriptElement;\n const scriptText = scriptNode.textContent || \"\";\n const shouldValidate = !scriptNode.src;\n\n if (shouldValidate) {\n try {\n // Validate script is syntactically complete before executing\n\n new Function(scriptText);\n } catch {\n scriptNode.remove();\n return;\n }\n }\n\n try {\n body.appendChild(scriptNode);\n appendedScriptsRef.current.push(scriptNode);\n } catch {\n scriptNode.remove();\n }\n } else {\n // Defer execution until all script tags are fully received\n node.remove();\n }\n });\n requestAnimationFrame(() => {\n if (hasStyles) {\n settleStateWithMinimumDelay(\n setIsGeneratingStyles,\n styleTimerRef,\n styleStartRef,\n () => {\n hasStylesRef.current = false;\n }\n );\n }\n if (hasScripts) {\n settleStateWithMinimumDelay(\n setIsGeneratingScripts,\n scriptTimerRef,\n scriptStartRef,\n () => {\n hasScriptsRef.current = false;\n }\n );\n }\n });\n }, [html, resetToken]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n },\n []\n );\n\n const overlayMessage = (() => {\n if (isGeneratingScripts || hasScriptsRef.current)\n return scriptLoadingText || \"Building scripts cache...\";\n if (isGeneratingStyles || hasStylesRef.current)\n return styleLoadingText || \"Building styles...\";\n if (isWaitingFirstDiv) return loadingText || \"Loading...\";\n return null;\n })();\n\n const handleToggleFullscreen = () => {\n const wrapper = wrapperRef.current;\n if (!wrapper) return;\n if (!document.fullscreenElement) {\n wrapper.requestFullscreen?.().catch(() => {});\n return;\n }\n document.exitFullscreen?.();\n };\n\n return (\n <div\n ref={wrapperRef}\n style={{ position: \"relative\", minHeight: 120 }}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n style={{\n pointerEvents: overlayMessage ? \"none\" : undefined,\n }}\n />\n <button\n type=\"button\"\n onClick={handleToggleFullscreen}\n style={{\n position: \"absolute\",\n top: 8,\n right: 8,\n zIndex: 30,\n padding: \"6px 10px\",\n borderRadius: 6,\n border: \"1px solid #cbd5e1\",\n background: \"#ffffffcc\",\n color: \"#0f172a\",\n fontSize: 12,\n fontWeight: 600,\n cursor: \"pointer\",\n boxShadow: \"0 4px 10px rgba(15, 23, 42, 0.08)\",\n }}\n >\n {isFullscreen\n ? fullScreenButtonText || \"Exit Fullscreen\"\n : fullScreenButtonText || \"Fullscreen\"}\n </button>\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["SandboxApp","html","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","resetToken","wrapperRef","useRef","containerRef","isWaitingFirstDiv","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","isFullscreen","setIsFullscreen","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","onFullscreenChange","doc","styleId","styleEl","container","body","node","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","handleToggleFullscreen","jsxs","jsx","Loader2"],"mappings":";;;AAYA,MAAMA,KAAwC,CAAC;AAAA,EAC7C,MAAAC;AAAA,EACA,aAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,YAAAC,IAAa;AACf,MAAM;AACJ,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAeD,EAAuB,IAAI,GAC1C,CAACE,GAAmBC,CAAoB,IAAIC,EAAS,EAAI,GACzD,CAACC,GAAoBC,CAAqB,IAAIF,EAAS,EAAK,GAC5D,CAACG,GAAqBC,CAAsB,IAAIJ,EAAS,EAAK,GAC9D,CAACK,GAAcC,CAAe,IAAIN,EAAS,EAAK,GAChDO,IAAoBX,EAA2B,EAAE,GACjDY,IAAqBZ,EAA4B,EAAE,GACnDa,IAAgBb,EAAO,CAAC,GACxBc,IAAiBd,EAAO,CAAC,GACzBe,IAAgBf,EAAsB,IAAI,GAC1CgB,IAAiBhB,EAAsB,IAAI,GAC3CiB,IAAejB,EAAO,EAAK,GAC3BkB,IAAgBlB,EAAO,EAAK,GAC5BmB,IAAwBnB,EAAO,EAAK,GACpCoB,IAAoBpB,EAAOF,CAAU,GACrCuB,IAAiB,KAEjBC,IAAa,CAACC,MAAoD;AACtE,IAAIA,EAAS,YACX,aAAaA,EAAS,OAAO,GAC7BA,EAAS,UAAU;AAAA,EAEvB,GAEMC,IAA8B,CAClCC,GACAF,GACAG,GACAC,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UAAA;AAAA,QAAA;AAAA,QAE7BwD,KACCE,gBAAAA,EAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,UAAU;AAAA,cACV,OAAO;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,KAAK;AAAA,cACL,eAAe;AAAA,cACf,QAAQ;AAAA,YAAA;AAAA,YAGV,UAAA;AAAA,cAAAC,gBAAAA,EAAAA;AAAAA,gBAACC;AAAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
1
+ {"version":3,"file":"SandboxApp.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { Loader2 } from \"lucide-react\";\n\nexport interface SandboxAppProps {\n html: string;\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [isWaitingFirstDiv, setIsWaitingFirstDiv] = useState(true);\n const [isGeneratingStyles, setIsGeneratingStyles] = useState(false);\n const [isGeneratingScripts, setIsGeneratingScripts] = useState(false);\n const appendedStylesRef = useRef<HTMLStyleElement[]>([]);\n const appendedScriptsRef = useRef<HTMLScriptElement[]>([]);\n const styleStartRef = useRef(0);\n const scriptStartRef = useRef(0);\n const styleTimerRef = useRef<number | null>(null);\n const scriptTimerRef = useRef<number | null>(null);\n const hasStylesRef = useRef(false);\n const hasScriptsRef = useRef(false);\n const hasRenderedContentRef = useRef(false);\n const prevResetTokenRef = useRef(resetToken);\n const MIN_LOADING_MS = 200;\n\n const clearTimer = (timerRef: React.MutableRefObject<number | null>) => {\n if (timerRef.current) {\n clearTimeout(timerRef.current);\n timerRef.current = null;\n }\n };\n\n const settleStateWithMinimumDelay = (\n setter: React.Dispatch<React.SetStateAction<boolean>>,\n timerRef: React.MutableRefObject<number | null>,\n startRef: React.MutableRefObject<number>,\n onDone?: () => void\n ) => {\n const elapsed = performance.now() - startRef.current;\n const delay = Math.max(0, MIN_LOADING_MS - elapsed);\n clearTimer(timerRef);\n timerRef.current = window.setTimeout(() => {\n setter(false);\n onDone?.();\n timerRef.current = null;\n }, delay);\n };\n\n useEffect(() => {\n const doc = containerRef.current?.ownerDocument;\n if (!doc) return;\n const styleId = \"sandbox-spinner-style\";\n let styleEl = doc.getElementById(styleId) as HTMLStyleElement | null;\n if (!styleEl) {\n styleEl = doc.createElement(\"style\");\n styleEl.id = styleId;\n styleEl.textContent =\n \"@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\";\n doc.head?.appendChild(styleEl);\n }\n }, []);\n\n useEffect(() => {\n if (resetToken !== prevResetTokenRef.current) {\n hasRenderedContentRef.current = false;\n prevResetTokenRef.current = resetToken;\n }\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n\n const container = containerRef.current;\n if (!container) return;\n const doc = container.ownerDocument;\n const body = doc?.body;\n if (!body) return;\n\n appendedStylesRef.current.forEach((node) => node.remove());\n appendedStylesRef.current = [];\n appendedScriptsRef.current.forEach((node) => node.remove());\n appendedScriptsRef.current = [];\n\n const hasRenderedBefore = hasRenderedContentRef.current;\n setIsWaitingFirstDiv(!hasRenderedBefore);\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n container.innerHTML = \"\";\n const wrapper = document.createElement(\"div\");\n wrapper.innerHTML = html;\n\n const openScriptCount = (html.match(/<script[\\s>]/gi) || []).length;\n const closeScriptCount = (html.match(/<\\/script>/gi) || []).length;\n const shouldExecuteScripts =\n openScriptCount > 0 && openScriptCount === closeScriptCount;\n\n const resourceQueue: HTMLElement[] = [];\n\n Array.from(wrapper.querySelectorAll(\"style, script\")).forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n const cloned = doc.createElement(\"style\");\n cloned.textContent = node.textContent || \"\";\n Array.from(node.attributes).forEach((attr) => {\n cloned.setAttribute(attr.name, attr.value);\n });\n resourceQueue.push(cloned);\n } else {\n const replacement = doc.createElement(\"script\");\n Array.from(node.attributes).forEach((attr) => {\n replacement.setAttribute(attr.name, attr.value);\n });\n replacement.textContent = node.textContent || \"\";\n resourceQueue.push(replacement);\n }\n node.remove();\n });\n\n const hasStyles = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"style\"\n );\n const hasScripts = resourceQueue.some(\n (node) => node.tagName.toLowerCase() === \"script\"\n );\n if (hasStyles) {\n hasStylesRef.current = true;\n styleStartRef.current = performance.now();\n clearTimer(styleTimerRef);\n setIsGeneratingStyles(true);\n }\n if (hasScripts) {\n hasScriptsRef.current = true;\n scriptStartRef.current = performance.now();\n clearTimer(scriptTimerRef);\n setIsGeneratingScripts(true);\n }\n\n const hasFirstElement = !!wrapper.firstElementChild;\n setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.append(...contentNodes);\n\n resourceQueue.forEach((node) => {\n if (node.tagName.toLowerCase() === \"style\") {\n doc.head?.appendChild(node);\n appendedStylesRef.current.push(node as HTMLStyleElement);\n return;\n }\n\n if (shouldExecuteScripts) {\n const scriptNode = node as HTMLScriptElement;\n const scriptText = scriptNode.textContent || \"\";\n const shouldValidate = !scriptNode.src;\n\n if (shouldValidate) {\n try {\n // Validate script is syntactically complete before executing\n\n new Function(scriptText);\n } catch {\n scriptNode.remove();\n return;\n }\n }\n\n try {\n body.appendChild(scriptNode);\n appendedScriptsRef.current.push(scriptNode);\n } catch {\n scriptNode.remove();\n }\n } else {\n // Defer execution until all script tags are fully received\n node.remove();\n }\n });\n requestAnimationFrame(() => {\n if (hasStyles) {\n settleStateWithMinimumDelay(\n setIsGeneratingStyles,\n styleTimerRef,\n styleStartRef,\n () => {\n hasStylesRef.current = false;\n }\n );\n }\n if (hasScripts) {\n settleStateWithMinimumDelay(\n setIsGeneratingScripts,\n scriptTimerRef,\n scriptStartRef,\n () => {\n hasScriptsRef.current = false;\n }\n );\n }\n });\n }, [html, resetToken]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n },\n []\n );\n\n const overlayMessage = (() => {\n if (isGeneratingScripts || hasScriptsRef.current)\n return scriptLoadingText || \"Building scripts cache...\";\n if (isGeneratingStyles || hasStylesRef.current)\n return styleLoadingText || \"Building styles...\";\n if (isWaitingFirstDiv) return loadingText || \"Loading...\";\n return null;\n })();\n\n return (\n <div\n ref={wrapperRef}\n style={{\n position: \"relative\",\n height: \"100vh\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n }}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n style={{\n pointerEvents: overlayMessage ? \"none\" : undefined,\n }}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["SandboxApp","html","loadingText","styleLoadingText","scriptLoadingText","resetToken","wrapperRef","useRef","containerRef","isWaitingFirstDiv","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","doc","styleId","styleEl","container","body","node","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","jsxs","jsx","Loader2"],"mappings":";;;AAWA,MAAMA,IAAwC,CAAC;AAAA,EAC7C,MAAAC;AAAA,EACA,aAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,YAAAC,IAAa;AACf,MAAM;AACJ,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAeD,EAAuB,IAAI,GAC1C,CAACE,GAAmBC,CAAoB,IAAIC,EAAS,EAAI,GACzD,CAACC,GAAoBC,CAAqB,IAAIF,EAAS,EAAK,GAC5D,CAACG,GAAqBC,CAAsB,IAAIJ,EAAS,EAAK,GAC9DK,IAAoBT,EAA2B,EAAE,GACjDU,IAAqBV,EAA4B,EAAE,GACnDW,IAAgBX,EAAO,CAAC,GACxBY,IAAiBZ,EAAO,CAAC,GACzBa,IAAgBb,EAAsB,IAAI,GAC1Cc,IAAiBd,EAAsB,IAAI,GAC3Ce,IAAef,EAAO,EAAK,GAC3BgB,IAAgBhB,EAAO,EAAK,GAC5BiB,IAAwBjB,EAAO,EAAK,GACpCkB,IAAoBlB,EAAOF,CAAU,GACrCqB,IAAiB,KAEjBC,IAAa,CAACC,MAAoD;AACtE,IAAIA,EAAS,YACX,aAAaA,EAAS,OAAO,GAC7BA,EAAS,UAAU;AAAA,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C,KAAuBS,EAAc,UAChCnB,KAAqB,8BAC1BQ,KAAsBU,EAAa,UAC9BnB,KAAoB,uBACzBM,IAA0BP,KAAe,eACtC;AAGT,SACEwD,gBAAAA,EAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,KAAKpD;AAAA,MACL,OAAO;AAAA,QACL,UAAU;AAAA,QACV,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,eAAe;AAAA,QACf,gBAAgB;AAAA,MAAA;AAAA,MAElB,aAAW,CAAC,CAACmD;AAAA,MAEb,UAAA;AAAA,QAAAE,gBAAAA,EAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,KAAKnD;AAAA,YACL,OAAO;AAAA,cACL,eAAeiD,IAAiB,SAAS;AAAA,YAAA;AAAA,UAC3C;AAAA,QAAA;AAAA,QAEDA,KACCC,gBAAAA,EAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,UAAU;AAAA,cACV,OAAO;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,KAAK;AAAA,cACL,eAAe;AAAA,cACf,QAAQ;AAAA,YAAA;AAAA,YAGV,UAAA;AAAA,cAAAC,gBAAAA,EAAAA;AAAAA,gBAACC;AAAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDH;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
@@ -4,5 +4,8 @@ export type RenderSegment = {
4
4
  } | {
5
5
  type: "sandbox";
6
6
  value: string;
7
+ } | {
8
+ type: "text";
9
+ value: string;
7
10
  };
8
- export declare const splitContentSegments: (raw: string) => RenderSegment[];
11
+ export declare const splitContentSegments: (raw: string, keepText?: boolean) => RenderSegment[];
@@ -1,35 +1,66 @@
1
- const r = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\s>]/i, m = [
1
+ const S = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)[\s>]/i, y = [
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
- ], a = /<\/[a-z][^>]*>\s*\n(?=[^\s<])/gi, h = (e, n) => {
7
- let s = e.length, t;
8
- for (a.lastIndex = 0; t = a.exec(e); )
9
- if (!(t.index <= n)) {
10
- s = t.index + t[0].length;
6
+ ], p = /<\/[a-z][^>]*>\s*\n(?=[^\s<])/gi, k = (t, e) => {
7
+ let i = t.length, n;
8
+ for (p.lastIndex = 0; n = p.exec(t); )
9
+ if (!(n.index <= e)) {
10
+ i = n.index + n[0].length;
11
11
  break;
12
12
  }
13
- return s;
14
- }, x = (e) => {
15
- let n = null;
16
- return m.forEach((s) => {
17
- const t = s.exec(e);
18
- if (!t || typeof t.index != "number") return;
19
- const i = t.index, c = t.index + t[0].length;
20
- (!n || i < n.start) && (n = { start: i, end: c });
21
- }), n;
22
- }, u = (e) => {
23
- const n = e.search(r), s = x(e);
24
- if (n === -1 && !s)
25
- return [];
26
- const t = !!s && (n === -1 || s.start < n), i = t ? s.start : n, c = t ? s.end : h(e, i), o = [], d = e.slice(i, c), l = e.slice(c);
27
- return o.push({
28
- type: t ? "markdown" : "sandbox",
29
- value: d
30
- }), l.trim() && o.push(...u(l)), o;
13
+ return i;
14
+ }, I = (t) => {
15
+ let e = null;
16
+ return y.forEach((i) => {
17
+ const n = i.exec(t);
18
+ if (!n || typeof n.index != "number") return;
19
+ const s = n.index, r = n.index + n[0].length;
20
+ (!e || s < e.start) && (e = { start: s, end: r });
21
+ }), e;
22
+ }, B = (t) => {
23
+ const e = t.search(/^\s*\|.*\|\s*$/m);
24
+ if (e === -1) return null;
25
+ const i = t.slice(e).split(`
26
+ `);
27
+ let n = e;
28
+ const s = [];
29
+ for (const c of i) {
30
+ if (!c.trim().startsWith("|")) break;
31
+ s.push(c), n += c.length + 1;
32
+ }
33
+ const r = s.join(`
34
+ `);
35
+ return { start: e, block: r, end: n - 1 };
36
+ }, f = (t, e = !1) => {
37
+ const i = t.indexOf("```");
38
+ if (e && i !== -1 && t.indexOf("```", i + 3) === -1)
39
+ return [{ type: "markdown", value: t }];
40
+ const n = t.search(/<svg\b/i);
41
+ if (n !== -1 && t.indexOf("</svg>", n) === -1)
42
+ return [{ type: "markdown", value: t }];
43
+ const s = B(t);
44
+ if (s) {
45
+ const l = [], b = t.slice(0, s.start);
46
+ e && b.trim() && l.push({ type: "text", value: b.trim() }), l.push({ type: "markdown", value: s.block });
47
+ const u = t.slice(s.end);
48
+ return u.trim() && l.push(
49
+ ...e ? f(u, !0) : f(u)
50
+ ), l;
51
+ }
52
+ if (t.match(/<svg[\s\S]*?<\/svg>/i) && e)
53
+ return t.trim().toLowerCase().endsWith("</svg>") ? [{ type: "markdown", value: t }] : [{ type: "markdown", value: `${t}</svg>` }];
54
+ const c = t.search(S), o = I(t);
55
+ if (c === -1 && !o)
56
+ return e && t.trim() ? [{ type: "text", value: t }] : [];
57
+ const d = !!o && (c === -1 || o.start < c), m = d ? o.start : c, h = d ? o.end : k(t, m), a = [], g = t.slice(0, m), x = t.slice(m, h), v = t.slice(h);
58
+ return e && g.trim() && a.push({ type: "text", value: g }), a.push({
59
+ type: d ? "markdown" : "sandbox",
60
+ value: x
61
+ }), v.trim() && a.push(...f(v, e)), a;
31
62
  };
32
63
  export {
33
- u as splitContentSegments
64
+ f as splitContentSegments
34
65
  };
35
66
  //# sourceMappingURL=split-content.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"split-content.js","sources":["../../../../src/components/ContentRender/utils/split-content.ts"],"sourcesContent":["export type RenderSegment =\n | { type: \"markdown\"; value: string }\n | { type: \"sandbox\"; 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];\n\nconst closingBoundary = /<\\/[a-z][^>]*>\\s*\\n(?=[^\\s<])/gi;\n\ntype MatchResult = { start: number; end: number };\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 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\n// Split incoming markdown content into markdown and sandbox HTML segments\nexport const splitContentSegments = (raw: string): RenderSegment[] => {\n const sandboxStartIndex = raw.search(SANDBOX_START_PATTERN);\n const inlineMatch = findInlineSandboxMatch(raw);\n\n if (sandboxStartIndex === -1 && !inlineMatch) {\n return [];\n }\n\n const shouldUseInline =\n !!inlineMatch &&\n (sandboxStartIndex === -1 || inlineMatch.start < sandboxStartIndex);\n\n const startIndex = shouldUseInline ? inlineMatch!.start : sandboxStartIndex;\n const blockEnd = shouldUseInline\n ? inlineMatch!.end\n : findHtmlBlockEnd(raw, startIndex);\n\n const segments: RenderSegment[] = [];\n const matchedBlock = raw.slice(startIndex, blockEnd);\n const after = raw.slice(blockEnd);\n\n segments.push({\n type: shouldUseInline ? \"markdown\" : \"sandbox\",\n value: matchedBlock,\n });\n\n if (after.trim()) {\n segments.push(...splitContentSegments(after));\n }\n\n return segments;\n};\n"],"names":["SANDBOX_START_PATTERN","INLINE_SANDBOX_PATTERNS","closingBoundary","findHtmlBlockEnd","raw","startIndex","blockEnd","match","findInlineSandboxMatch","earliest","pattern","start","end","splitContentSegments","sandboxStartIndex","inlineMatch","shouldUseInline","segments","matchedBlock","after"],"mappings":"AAIA,MAAMA,IACJ,sGAEIC,IAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEMC,IAAkB,mCAIlBC,IAAmB,CAACC,GAAaC,MAAuB;AAC5D,MAAIC,IAAWF,EAAI,QACfG;AAGJ,OAFAL,EAAgB,YAAY,GAEpBK,IAAQL,EAAgB,KAAKE,CAAG;AACtC,QAAI,EAAAG,EAAM,SAASF,IACnB;AAAA,MAAAC,IAAWC,EAAM,QAAQA,EAAM,CAAC,EAAE;AAClC;AAAA;AAGF,SAAOD;AACT,GAEME,IAAyB,CAACJ,MAAoC;AAClE,MAAIK,IAA+B;AAEnC,SAAAR,EAAwB,QAAQ,CAACS,MAAY;AAC3C,UAAMH,IAAQG,EAAQ,KAAKN,CAAG;AAC9B,QAAI,CAACG,KAAS,OAAOA,EAAM,SAAU,SAAU;AAC/C,UAAMI,IAAQJ,EAAM,OACdK,IAAML,EAAM,QAAQA,EAAM,CAAC,EAAE;AAEnC,KAAI,CAACE,KAAYE,IAAQF,EAAS,WAChCA,IAAW,EAAE,OAAAE,GAAO,KAAAC,EAAA;AAAA,EAExB,CAAC,GAEMH;AACT,GAGaI,IAAuB,CAACT,MAAiC;AACpE,QAAMU,IAAoBV,EAAI,OAAOJ,CAAqB,GACpDe,IAAcP,EAAuBJ,CAAG;AAE9C,MAAIU,MAAsB,MAAM,CAACC;AAC/B,WAAO,CAAA;AAGT,QAAMC,IACJ,CAAC,CAACD,MACDD,MAAsB,MAAMC,EAAY,QAAQD,IAE7CT,IAAaW,IAAkBD,EAAa,QAAQD,GACpDR,IAAWU,IACbD,EAAa,MACbZ,EAAiBC,GAAKC,CAAU,GAE9BY,IAA4B,CAAA,GAC5BC,IAAed,EAAI,MAAMC,GAAYC,CAAQ,GAC7Ca,IAAQf,EAAI,MAAME,CAAQ;AAEhC,SAAAW,EAAS,KAAK;AAAA,IACZ,MAAMD,IAAkB,aAAa;AAAA,IACrC,OAAOE;AAAA,EAAA,CACR,GAEGC,EAAM,UACRF,EAAS,KAAK,GAAGJ,EAAqBM,CAAK,CAAC,GAGvCF;AACT;"}
1
+ {"version":3,"file":"split-content.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];\n\nconst closingBoundary = /<\\/[a-z][^>]*>\\s*\\n(?=[^\\s<])/gi;\n\ntype MatchResult = { start: number; end: number };\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 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 extractTableBlock = (\n raw: string\n): { start: number; block: string; end: number } | null => {\n const tableStart = raw.search(/^\\s*\\|.*\\|\\s*$/m);\n if (tableStart === -1) return null;\n\n const lines = raw.slice(tableStart).split(\"\\n\");\n let endIndex = tableStart;\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 endIndex += line.length + 1; // include newline\n }\n\n const block = tableLines.join(\"\\n\");\n return { start: tableStart, block, end: endIndex - 1 };\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 fenceStart = raw.indexOf(\"```\");\n if (keepText && fenceStart !== -1) {\n const closingFence = raw.indexOf(\"```\", fenceStart + 3);\n if (closingFence === -1) {\n return [{ type: \"markdown\", value: raw }];\n }\n }\n\n const svgOpenIndex = raw.search(/<svg\\b/i);\n if (svgOpenIndex !== -1 && raw.indexOf(\"</svg>\", svgOpenIndex) === -1) {\n return [{ type: \"markdown\", value: raw }];\n }\n\n const tableBlock = extractTableBlock(raw);\n if (tableBlock) {\n const segments: RenderSegment[] = [];\n const before = raw.slice(0, tableBlock.start);\n if (keepText && before.trim()) {\n segments.push({ type: \"text\", value: before.trim() });\n }\n segments.push({ type: \"markdown\", value: tableBlock.block });\n const after = raw.slice(tableBlock.end);\n if (after.trim()) {\n segments.push(\n ...(keepText\n ? splitContentSegments(after, true)\n : splitContentSegments(after))\n );\n }\n return segments;\n }\n\n const completeSvgMatch = raw.match(/<svg[\\s\\S]*?<\\/svg>/i);\n if (completeSvgMatch && keepText) {\n if (!raw.trim().toLowerCase().endsWith(\"</svg>\")) {\n return [{ type: \"markdown\", value: `${raw}</svg>` }];\n }\n return [{ type: \"markdown\", value: raw }];\n }\n\n const sandboxStartIndex = raw.search(SANDBOX_START_PATTERN);\n const inlineMatch = findInlineSandboxMatch(raw);\n\n if (sandboxStartIndex === -1 && !inlineMatch) {\n if (keepText && raw.trim()) {\n return [{ type: \"text\", value: raw }];\n }\n return [];\n }\n\n const shouldUseInline =\n !!inlineMatch &&\n (sandboxStartIndex === -1 || inlineMatch.start < sandboxStartIndex);\n\n const startIndex = shouldUseInline ? inlineMatch!.start : sandboxStartIndex;\n const blockEnd = shouldUseInline\n ? inlineMatch!.end\n : findHtmlBlockEnd(raw, startIndex);\n\n const segments: RenderSegment[] = [];\n const before = raw.slice(0, startIndex);\n const matchedBlock = raw.slice(startIndex, blockEnd);\n const after = raw.slice(blockEnd);\n\n if (keepText && before.trim()) {\n segments.push({ type: \"text\", value: before });\n }\n\n segments.push({\n type: shouldUseInline ? \"markdown\" : \"sandbox\",\n value: matchedBlock,\n });\n\n if (after.trim()) {\n segments.push(...splitContentSegments(after, keepText));\n }\n\n return segments;\n};\n"],"names":["SANDBOX_START_PATTERN","INLINE_SANDBOX_PATTERNS","closingBoundary","findHtmlBlockEnd","raw","startIndex","blockEnd","match","findInlineSandboxMatch","earliest","pattern","start","end","extractTableBlock","tableStart","lines","endIndex","tableLines","line","block","splitContentSegments","keepText","fenceStart","svgOpenIndex","tableBlock","segments","before","after","sandboxStartIndex","inlineMatch","shouldUseInline","matchedBlock"],"mappings":"AAKA,MAAMA,IACJ,sGAEIC,IAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEMC,IAAkB,mCAIlBC,IAAmB,CAACC,GAAaC,MAAuB;AAC5D,MAAIC,IAAWF,EAAI,QACfG;AAGJ,OAFAL,EAAgB,YAAY,GAEpBK,IAAQL,EAAgB,KAAKE,CAAG;AACtC,QAAI,EAAAG,EAAM,SAASF,IACnB;AAAA,MAAAC,IAAWC,EAAM,QAAQA,EAAM,CAAC,EAAE;AAClC;AAAA;AAGF,SAAOD;AACT,GAEME,IAAyB,CAACJ,MAAoC;AAClE,MAAIK,IAA+B;AAEnC,SAAAR,EAAwB,QAAQ,CAACS,MAAY;AAC3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