markdown-flow-ui 0.1.112 → 0.1.113
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.
- package/dist/_virtual/index.cjs8.js +1 -1
- package/dist/_virtual/index.cjs9.js +1 -1
- package/dist/_virtual/index.es8.js +2 -3
- package/dist/_virtual/index.es8.js.map +1 -1
- package/dist/_virtual/index.es9.js +3 -2
- package/dist/_virtual/index.es9.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
- package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.d.ts +1 -0
- package/dist/components/ContentRender/ContentRender.es.js +118 -116
- package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
- package/dist/components/ContentRender/IframeSandbox.cjs.js +2 -2
- package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
- package/dist/components/ContentRender/IframeSandbox.d.ts +1 -0
- package/dist/components/ContentRender/IframeSandbox.es.js +108 -100
- package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
- package/dist/components/ContentRender/SandboxApp.cjs.js +2 -2
- package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
- package/dist/components/ContentRender/SandboxApp.d.ts +1 -0
- package/dist/components/ContentRender/SandboxApp.es.js +90 -87
- package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
- package/dist/components/Slide/Slide.cjs.js +1 -1
- package/dist/components/Slide/Slide.cjs.js.map +1 -1
- package/dist/components/Slide/Slide.d.ts +1 -0
- package/dist/components/Slide/Slide.es.js +524 -503
- package/dist/components/Slide/Slide.es.js.map +1 -1
- package/dist/components/Slide/Slide.stories.d.ts +1 -0
- package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.es.js +1 -1
- package/dist/markdown-flow-ui-lib.css +1 -1
- package/package.json +1 -1
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { j as t } from "../../_virtual/jsx-runtime.es.js";
|
|
2
2
|
/* empty css */
|
|
3
3
|
/* empty css */
|
|
4
|
-
import X, { useMemo as h, useRef as
|
|
5
|
-
import
|
|
6
|
-
import { sanitizeInvalidTagName as
|
|
7
|
-
import { stripSvgTextLineBreaks as
|
|
4
|
+
import X, { useMemo as h, useRef as E, useEffect as F } from "react";
|
|
5
|
+
import se from "../../_virtual/index.es.js";
|
|
6
|
+
import { sanitizeInvalidTagName as oe } from "./utils/sanitize-invalid-tag-name.es.js";
|
|
7
|
+
import { stripSvgTextLineBreaks as ae } from "./utils/strip-svg-text-line-breaks.es.js";
|
|
8
8
|
/* empty css */
|
|
9
9
|
/* empty css */
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import { preserveCustomVariableProperties as
|
|
15
|
-
import { subsetLanguages as
|
|
16
|
-
import { parseMarkdownSegments as J, mermaidBlockIsComplete as
|
|
17
|
-
import { normalizeInlineHtml as
|
|
18
|
-
import
|
|
19
|
-
import { splitContentSegments as
|
|
20
|
-
import { getInteractionDefaultValues as
|
|
21
|
-
import { Markdown as
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
import
|
|
28
|
-
const
|
|
29
|
-
const o =
|
|
30
|
-
return
|
|
10
|
+
import ie from "./CodeBlock.es.js";
|
|
11
|
+
import le from "./plugins/CustomVariable.es.js";
|
|
12
|
+
import W from "./plugins/MermaidChart.es.js";
|
|
13
|
+
import ce from "./useTypewriterStateMachine.es.js";
|
|
14
|
+
import { preserveCustomVariableProperties as me, restoreCustomVariableProperties as de } from "./utils/custom-variable-props.es.js";
|
|
15
|
+
import { subsetLanguages as ue, highlightLanguages as pe } from "./utils/highlight-languages.es.js";
|
|
16
|
+
import { parseMarkdownSegments as J, mermaidBlockIsComplete as he } from "./utils/mermaid-parse.es.js";
|
|
17
|
+
import { normalizeInlineHtml as Q } from "./utils/normalize-inline-html.es.js";
|
|
18
|
+
import fe from "./IframeSandbox.es.js";
|
|
19
|
+
import { splitContentSegments as xe } from "./utils/split-content.es.js";
|
|
20
|
+
import { getInteractionDefaultValues as ve } from "../../lib/interaction-defaults.es.js";
|
|
21
|
+
import { Markdown as ge } from "../../markdown-flow-ui/node_modules/.pnpm/react-markdown@10.1.0_@types_react@19.2.2_react@19.0.1/node_modules/react-markdown/lib/index.es.js";
|
|
22
|
+
import be from "../../markdown-flow-ui/node_modules/.pnpm/rehype-raw@7.0.0/node_modules/rehype-raw/lib/index.es.js";
|
|
23
|
+
import ye from "../../markdown-flow-ui/node_modules/.pnpm/rehype-highlight@7.0.2/node_modules/rehype-highlight/lib/index.es.js";
|
|
24
|
+
import Ne from "../../markdown-flow-ui/node_modules/.pnpm/rehype-katex@7.0.1/node_modules/rehype-katex/lib/index.es.js";
|
|
25
|
+
import je from "../../markdown-flow-ui/node_modules/.pnpm/remark-gfm@4.0.1/node_modules/remark-gfm/lib/index.es.js";
|
|
26
|
+
import ke from "../../markdown-flow-ui/node_modules/.pnpm/remark-math@6.0.0/node_modules/remark-math/lib/index.es.js";
|
|
27
|
+
import we from "../../markdown-flow-ui/node_modules/.pnpm/remark-breaks@4.0.0/node_modules/remark-breaks/lib/index.es.js";
|
|
28
|
+
const Se = /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)\b/i, Y = ({ svg: r }) => {
|
|
29
|
+
const o = E(null);
|
|
30
|
+
return F(() => {
|
|
31
31
|
const a = o.current;
|
|
32
32
|
if (!a) return;
|
|
33
33
|
const i = a.shadowRoot ?? a.attachShadow({ mode: "open" }), y = "content-render-svg-style";
|
|
@@ -39,51 +39,51 @@ const we = /<(script|style|link|iframe|html|head|body|meta|title|base|template|d
|
|
|
39
39
|
`, i.appendChild(l)), Array.from(i.childNodes).filter(
|
|
40
40
|
(n) => n !== l
|
|
41
41
|
).forEach((n) => i.removeChild(n));
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
let N = !1,
|
|
42
|
+
const T = document.createElement("template"), z = ae(r);
|
|
43
|
+
T.innerHTML = z, i.append(T.content.cloneNode(!0));
|
|
44
|
+
let N = !1, C = !1;
|
|
45
45
|
i.querySelectorAll("svg").forEach((n) => {
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
const k =
|
|
46
|
+
const L = n.getAttribute("viewBox");
|
|
47
|
+
if (!L) return;
|
|
48
|
+
const k = L.trim().split(/[\s,]+/).map((c) => Number(c));
|
|
49
49
|
if (k.length !== 4 || k.some(Number.isNaN)) return;
|
|
50
|
-
const [, , f, p] = k, x = n.getAttribute("width"), v = n.getAttribute("height"),
|
|
50
|
+
const [, , f, p] = k, x = n.getAttribute("width"), v = n.getAttribute("height"), B = (c) => {
|
|
51
51
|
if (!c) return !1;
|
|
52
52
|
const m = c.trim().toLowerCase();
|
|
53
53
|
return m === "auto" || m.endsWith("%");
|
|
54
|
-
},
|
|
54
|
+
}, A = (c) => {
|
|
55
55
|
if (!c) return null;
|
|
56
56
|
const m = c.trim().toLowerCase();
|
|
57
57
|
if (m === "auto" || m.endsWith("%"))
|
|
58
58
|
return null;
|
|
59
|
-
const
|
|
60
|
-
return Number.isNaN(
|
|
61
|
-
},
|
|
62
|
-
if (
|
|
59
|
+
const S = Number.parseFloat(m);
|
|
60
|
+
return Number.isNaN(S) ? null : S;
|
|
61
|
+
}, M = B(x), I = B(v), w = !x || x === "0", g = !v || v === "0", V = A(x), H = A(v);
|
|
62
|
+
if (M || I || w && g || V === f && H === p) {
|
|
63
63
|
N = !0, n.classList.add("content-render-svg-el--responsive"), n.classList.remove("content-render-svg-el--fixed"), n.style.width = "100%", n.style.height = "auto", !n.style.aspectRatio && p > 0 && (n.style.aspectRatio = `${f} / ${p}`);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
C = !0, n.classList.add("content-render-svg-el--fixed"), n.classList.remove("content-render-svg-el--responsive"), w && f > 0 && n.setAttribute("width", `${f}`), g && p > 0 && n.setAttribute("height", `${p}`);
|
|
67
67
|
});
|
|
68
|
-
const j = N && !
|
|
68
|
+
const j = N && !C;
|
|
69
69
|
a.classList.toggle("content-render-svg--responsive", j), a.classList.toggle("content-render-svg--fixed", !j);
|
|
70
70
|
}, [r]), /* @__PURE__ */ t.jsx("div", { className: "content-render-svg-scroll", children: /* @__PURE__ */ t.jsx("div", { className: "content-render-svg", ref: o }) });
|
|
71
|
-
},
|
|
72
|
-
ce,
|
|
73
|
-
ge,
|
|
74
|
-
se,
|
|
71
|
+
}, Re = [je, ke, se, we], Te = [
|
|
75
72
|
me,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
be,
|
|
74
|
+
oe,
|
|
75
|
+
de,
|
|
76
|
+
[ye, { languages: pe, subset: ue }],
|
|
77
|
+
Ne
|
|
78
|
+
], Z = ({ content: r, components: o }) => /* @__PURE__ */ t.jsx("div", { className: "markdown-renderer", children: /* @__PURE__ */ t.jsx(
|
|
79
|
+
ge,
|
|
80
80
|
{
|
|
81
|
-
remarkPlugins:
|
|
82
|
-
rehypePlugins:
|
|
81
|
+
remarkPlugins: Re,
|
|
82
|
+
rehypePlugins: Te,
|
|
83
83
|
components: o,
|
|
84
84
|
children: r
|
|
85
85
|
}
|
|
86
|
-
) }),
|
|
86
|
+
) }), Ce = (r) => {
|
|
87
87
|
if (r.length <= 1) return r;
|
|
88
88
|
const o = [];
|
|
89
89
|
return r.forEach((a) => {
|
|
@@ -101,62 +101,63 @@ const we = /<(script|style|link|iframe|html|head|body|meta|title|base|template|d
|
|
|
101
101
|
}
|
|
102
102
|
o.push({ type: "markdown", value: a.value });
|
|
103
103
|
}), o;
|
|
104
|
-
},
|
|
104
|
+
}, rt = ({
|
|
105
105
|
content: r,
|
|
106
106
|
customRenderBar: o,
|
|
107
107
|
onSend: a,
|
|
108
108
|
typingSpeed: i = 30,
|
|
109
109
|
enableTypewriter: y = !1,
|
|
110
110
|
userInput: l,
|
|
111
|
-
interactionDefaultValueOptions:
|
|
112
|
-
defaultButtonText:
|
|
113
|
-
defaultInputText:
|
|
111
|
+
interactionDefaultValueOptions: $,
|
|
112
|
+
defaultButtonText: T,
|
|
113
|
+
defaultInputText: z,
|
|
114
114
|
defaultSelectedValues: N,
|
|
115
|
-
readonly:
|
|
115
|
+
readonly: C = !1,
|
|
116
116
|
onTypeFinished: j,
|
|
117
117
|
confirmButtonText: n,
|
|
118
|
-
copyButtonText:
|
|
118
|
+
copyButtonText: L,
|
|
119
119
|
copiedButtonText: k,
|
|
120
120
|
sandboxLoadingText: f,
|
|
121
121
|
sandboxStyleLoadingText: p,
|
|
122
122
|
sandboxScriptLoadingText: x,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
disableSandboxLoadingOverlay: v = !1,
|
|
124
|
+
sandboxFullscreenButtonText: B,
|
|
125
|
+
sandboxMode: A = "content",
|
|
126
|
+
onClickCustomButtonAfterContent: M,
|
|
126
127
|
beforeSend: I
|
|
127
128
|
// tooltipMinLength,
|
|
128
129
|
}) => {
|
|
129
|
-
const
|
|
130
|
-
() =>
|
|
130
|
+
const w = h(
|
|
131
|
+
() => Q(r),
|
|
131
132
|
[r]
|
|
132
133
|
), g = h(
|
|
133
|
-
() =>
|
|
134
|
+
() => ve(
|
|
134
135
|
r,
|
|
135
136
|
l,
|
|
136
|
-
|
|
137
|
+
$
|
|
137
138
|
),
|
|
138
|
-
[r,
|
|
139
|
-
),
|
|
139
|
+
[r, $, l]
|
|
140
|
+
), V = T?.trim() || g.buttonText, H = z?.trim() || g.inputText, G = h(
|
|
140
141
|
() => l ? l.split(",").map((e) => e.trim()).filter(Boolean) : void 0,
|
|
141
142
|
[l]
|
|
142
|
-
), U = N?.length ? N : g.selectedValues ||
|
|
143
|
+
), U = N?.length ? N : g.selectedValues || G, c = {
|
|
143
144
|
"custom-button-after-content": ({
|
|
144
145
|
children: e
|
|
145
146
|
}) => /* @__PURE__ */ t.jsx(
|
|
146
147
|
"button",
|
|
147
148
|
{
|
|
148
149
|
className: "content-render-custom-button-after-content",
|
|
149
|
-
onClick:
|
|
150
|
+
onClick: M,
|
|
150
151
|
children: /* @__PURE__ */ t.jsx("span", { className: "content-render-custom-button-after-content-inner", children: e })
|
|
151
152
|
}
|
|
152
153
|
),
|
|
153
154
|
"custom-variable": (e) => /* @__PURE__ */ t.jsx(
|
|
154
|
-
|
|
155
|
+
le,
|
|
155
156
|
{
|
|
156
157
|
...e,
|
|
157
|
-
readonly:
|
|
158
|
-
defaultButtonText:
|
|
159
|
-
defaultInputText:
|
|
158
|
+
readonly: C,
|
|
159
|
+
defaultButtonText: V,
|
|
160
|
+
defaultInputText: H,
|
|
160
161
|
defaultSelectedValues: U,
|
|
161
162
|
onSend: a,
|
|
162
163
|
beforeSend: I,
|
|
@@ -164,12 +165,12 @@ const we = /<(script|style|link|iframe|html|head|body|meta|title|base|template|d
|
|
|
164
165
|
}
|
|
165
166
|
),
|
|
166
167
|
code: (e) => {
|
|
167
|
-
const { className: s, children: d, ...
|
|
168
|
+
const { className: s, children: d, ..._ } = e;
|
|
168
169
|
if (/language-(\w+)/.exec(s || "")?.[1] === "mermaid") {
|
|
169
|
-
const b = d?.toString().replace(/\n$/, "") || "",
|
|
170
|
-
return /* @__PURE__ */ t.jsx(
|
|
170
|
+
const b = d?.toString().replace(/\n$/, "") || "", ne = he(r, b);
|
|
171
|
+
return /* @__PURE__ */ t.jsx(W, { chart: b, frozen: ne });
|
|
171
172
|
}
|
|
172
|
-
return /* @__PURE__ */ t.jsx("code", { className: s, ...
|
|
173
|
+
return /* @__PURE__ */ t.jsx("code", { className: s, ..._, children: d });
|
|
173
174
|
},
|
|
174
175
|
table: ({ ...e }) => /* @__PURE__ */ t.jsx("div", { className: "content-render-table-container", children: /* @__PURE__ */ t.jsx("table", { className: "content-render-table", ...e }) }),
|
|
175
176
|
th: ({ ...e }) => /* @__PURE__ */ t.jsx("th", { className: "content-render-th", ...e }),
|
|
@@ -192,56 +193,56 @@ const we = /<(script|style|link|iframe|html|head|body|meta|title|base|template|d
|
|
|
192
193
|
) : /* @__PURE__ */ t.jsx("input", { ...e }),
|
|
193
194
|
a: ({ children: e, ...s }) => /* @__PURE__ */ t.jsx("a", { target: "_blank", rel: "noopener noreferrer", ...s, children: e }),
|
|
194
195
|
pre: (e) => /* @__PURE__ */ t.jsx(
|
|
195
|
-
|
|
196
|
+
ie,
|
|
196
197
|
{
|
|
197
198
|
...e,
|
|
198
|
-
copyButtonText:
|
|
199
|
+
copyButtonText: L,
|
|
199
200
|
copiedButtonText: k
|
|
200
201
|
}
|
|
201
202
|
)
|
|
202
|
-
}, { displayContent:
|
|
203
|
+
}, { displayContent: m, isComplete: S } = ce({
|
|
203
204
|
// processMarkdownText will let code block printf("You win!\n") become printf("You win!<br/>");
|
|
204
205
|
// content: processMarkdownText(content),
|
|
205
|
-
content:
|
|
206
|
+
content: w,
|
|
206
207
|
typingSpeed: i,
|
|
207
208
|
disabled: !y
|
|
208
|
-
}),
|
|
209
|
-
() =>
|
|
209
|
+
}), q = y ? m : w, K = h(
|
|
210
|
+
() => Se.test(r),
|
|
210
211
|
[r]
|
|
211
|
-
),
|
|
212
|
-
() =>
|
|
213
|
-
[r,
|
|
214
|
-
),
|
|
212
|
+
), D = h(
|
|
213
|
+
() => K ? xe(r, !0) : [],
|
|
214
|
+
[r, K]
|
|
215
|
+
), R = D.some(
|
|
215
216
|
(e) => e.type === "sandbox"
|
|
216
|
-
), E = h(
|
|
217
|
-
() => Te(P),
|
|
218
|
-
[P]
|
|
219
217
|
), ee = h(
|
|
220
|
-
() =>
|
|
221
|
-
[
|
|
222
|
-
),
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
218
|
+
() => Ce(D),
|
|
219
|
+
[D]
|
|
220
|
+
), te = h(
|
|
221
|
+
() => J(q),
|
|
222
|
+
[q]
|
|
223
|
+
), P = E(!1);
|
|
224
|
+
F(() => {
|
|
225
|
+
R || S && !P.current && (P.current = !0, j?.());
|
|
226
|
+
}, [R, S, j]), F(() => {
|
|
227
|
+
R || (P.current = !1);
|
|
228
|
+
}, [R, r]);
|
|
229
|
+
const re = (e, s) => {
|
|
230
|
+
const d = Q(e);
|
|
231
|
+
return J(d).map((u, O) => {
|
|
232
|
+
const b = `${s}-${u.type}-${O}`;
|
|
232
233
|
return u.type === "text" ? /* @__PURE__ */ t.jsx(
|
|
233
|
-
|
|
234
|
+
Z,
|
|
234
235
|
{
|
|
235
|
-
components:
|
|
236
|
+
components: c,
|
|
236
237
|
content: u.value
|
|
237
238
|
},
|
|
238
239
|
b
|
|
239
|
-
) : u.type === "mermaid" ? /* @__PURE__ */ t.jsx(
|
|
240
|
+
) : u.type === "mermaid" ? /* @__PURE__ */ t.jsx(W, { chart: u.value, frozen: !u.complete }, b) : u.type === "svg" ? /* @__PURE__ */ t.jsx(Y, { svg: u.value }, b) : null;
|
|
240
241
|
});
|
|
241
242
|
};
|
|
242
|
-
return
|
|
243
|
+
return R ? /* @__PURE__ */ t.jsx("div", { className: "content-render markdown-body", children: ee.map(
|
|
243
244
|
(e, s) => e.type === "sandbox" ? /* @__PURE__ */ t.jsx(
|
|
244
|
-
|
|
245
|
+
fe,
|
|
245
246
|
{
|
|
246
247
|
hideFullScreen: !0,
|
|
247
248
|
type: "sandbox",
|
|
@@ -250,25 +251,26 @@ const we = /<(script|style|link|iframe|html|head|body|meta|title|base|template|d
|
|
|
250
251
|
loadingText: f,
|
|
251
252
|
styleLoadingText: p,
|
|
252
253
|
scriptLoadingText: x,
|
|
253
|
-
|
|
254
|
-
|
|
254
|
+
disableLoadingOverlay: v,
|
|
255
|
+
fullScreenButtonText: B,
|
|
256
|
+
mode: A
|
|
255
257
|
},
|
|
256
258
|
`sandbox-${s}`
|
|
257
|
-
) : /* @__PURE__ */ t.jsx(X.Fragment, { children:
|
|
259
|
+
) : /* @__PURE__ */ t.jsx(X.Fragment, { children: re(e.value, `md-${s}`) }, `md-${s}`)
|
|
258
260
|
) }) : /* @__PURE__ */ t.jsxs("div", { className: "content-render markdown-body", children: [
|
|
259
|
-
|
|
261
|
+
te.map((e, s) => {
|
|
260
262
|
if (e.type === "text")
|
|
261
263
|
return /* @__PURE__ */ t.jsx(
|
|
262
|
-
|
|
264
|
+
Z,
|
|
263
265
|
{
|
|
264
|
-
components:
|
|
266
|
+
components: c,
|
|
265
267
|
content: e.value
|
|
266
268
|
},
|
|
267
269
|
s
|
|
268
270
|
);
|
|
269
271
|
if (e.type === "mermaid")
|
|
270
272
|
return /* @__PURE__ */ t.jsx(
|
|
271
|
-
|
|
273
|
+
W,
|
|
272
274
|
{
|
|
273
275
|
chart: e.value,
|
|
274
276
|
frozen: !e.complete
|
|
@@ -276,17 +278,17 @@ const we = /<(script|style|link|iframe|html|head|body|meta|title|base|template|d
|
|
|
276
278
|
s
|
|
277
279
|
);
|
|
278
280
|
if (e.type === "svg")
|
|
279
|
-
return /* @__PURE__ */ t.jsx(
|
|
281
|
+
return /* @__PURE__ */ t.jsx(Y, { svg: e.value }, s);
|
|
280
282
|
}),
|
|
281
283
|
o && /* @__PURE__ */ t.jsx("div", { className: "content-render-custom-bar", children: X.createElement(o, {
|
|
282
284
|
content: r,
|
|
283
|
-
displayContent:
|
|
285
|
+
displayContent: m,
|
|
284
286
|
onSend: a
|
|
285
287
|
}) })
|
|
286
288
|
] });
|
|
287
289
|
};
|
|
288
290
|
export {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
+
Z as MarkdownRenderer,
|
|
292
|
+
rt as default
|
|
291
293
|
};
|
|
292
294
|
//# sourceMappingURL=ContentRender.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentRender.es.js","sources":["../../../src/components/ContentRender/ContentRender.tsx"],"sourcesContent":["import \"highlight.js/styles/github.css\";\nimport \"katex/dist/katex.min.css\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport ReactMarkdown from \"react-markdown\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeKatex from \"rehype-katex\";\nimport rehypeRaw from \"rehype-raw\";\nimport remarkBreaks from \"remark-breaks\";\nimport remarkFlow from \"remark-flow\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport { CustomRenderBarProps, OnSendContentParams } from \"../types\";\nimport { sanitizeInvalidTagName } from \"./utils/sanitize-invalid-tag-name\";\nimport { stripSvgTextLineBreaks } from \"./utils/strip-svg-text-line-breaks\";\nimport \"./contentRender.css\";\nimport \"./github-markdown-light.css\";\nimport CodeBlock from \"./CodeBlock\";\nimport CustomButtonInputVariable, {\n ComponentsWithCustomVariable,\n} from \"./plugins/CustomVariable\";\nimport MermaidChart from \"./plugins/MermaidChart\";\nimport useTypewriterStateMachine from \"./useTypewriterStateMachine\";\nimport {\n preserveCustomVariableProperties,\n restoreCustomVariableProperties,\n} from \"./utils/custom-variable-props\";\nimport {\n highlightLanguages,\n subsetLanguages,\n} from \"./utils/highlight-languages\";\n// import { processMarkdownText } from \"./utils/process-markdown\";\nimport {\n parseMarkdownSegments,\n mermaidBlockIsComplete,\n} from \"./utils/mermaid-parse\";\nimport { normalizeInlineHtml } from \"./utils/normalize-inline-html\";\nimport IframeSandbox from \"./IframeSandbox\";\nimport {\n splitContentSegments,\n type RenderSegment,\n} from \"./utils/split-content\";\nimport {\n getInteractionDefaultValues,\n type InteractionDefaultValueOptions,\n} from \"../../lib/interaction-defaults\";\n\nconst SANDBOX_TAG_HINT_PATTERN =\n /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)\\b/i;\n// Define component Props type\nexport interface ContentRenderProps {\n content: string;\n /**\n * Callback invoked when the custom button after content is clicked.\n * This button is rendered via the `<custom-button-after-content>` tag in markdown content.\n * @example\n * ```tsx\n * <ContentRender\n * content=\"Hello <custom-button-after-content>Ask</custom-button-after-content>\"\n * onClickCustomButtonAfterContent={() => console.log('Button clicked')}\n * />\n * ```\n */\n customRenderBar?: CustomRenderBarProps;\n onClickCustomButtonAfterContent?: () => void;\n onSend?: (content: OnSendContentParams) => void;\n typingSpeed?: number;\n enableTypewriter?: boolean;\n userInput?: string;\n interactionDefaultValueOptions?: InteractionDefaultValueOptions;\n defaultButtonText?: string;\n defaultInputText?: string; // Text input by user\n defaultSelectedValues?: string[]; // Default selected values for multi-select\n readonly?: boolean;\n onTypeFinished?: () => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n // Copy button text (i18n support)\n copyButtonText?: string;\n // Copied state text (i18n support)\n copiedButtonText?: string;\n // Dynamic interaction format for multi-select support\n dynamicInteractionFormat?: string;\n // Loading text before first HTML block renders inside iframe (i18n support)\n sandboxLoadingText?: string;\n // Loading text while styles are being generated inside iframe\n sandboxStyleLoadingText?: string;\n // Loading text while scripts are being cached/executed inside iframe\n sandboxScriptLoadingText?: string;\n // Fullscreen button text for iframe sandbox\n sandboxFullscreenButtonText?: string;\n // Sandbox render mode\n sandboxMode?: \"content\" | \"blackboard\";\n beforeSend?: (param: OnSendContentParams) => boolean;\n // tooltipMinLength?: number; // Control minimum character length for tooltip display, default 10\n}\n\n// Render svg string via Shadow DOM to avoid markdown wrapping\nconst SvgBlockInShadow: React.FC<{ svg: string }> = ({ svg }) => {\n const hostRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const shadowRoot = host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n const styleId = \"content-render-svg-style\";\n let styleEl = shadowRoot.getElementById(styleId) as HTMLStyleElement | null;\n\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.id = styleId;\n // Keep intrinsic SVG width so the wrapper can scroll horizontally when needed\n styleEl.textContent = `\n svg { height: auto; display: inline-block; }\n svg.content-render-svg-el--responsive { width: 100%; max-width: 100%; }\n svg.content-render-svg-el--fixed { max-width: none; }\n `;\n shadowRoot.appendChild(styleEl);\n }\n\n const nodesToRemove = Array.from(shadowRoot.childNodes).filter(\n (node) => node !== styleEl\n );\n nodesToRemove.forEach((node) => shadowRoot.removeChild(node));\n\n const template = document.createElement(\"template\");\n const cleanedSvg = stripSvgTextLineBreaks(svg);\n template.innerHTML = cleanedSvg;\n shadowRoot.append(template.content.cloneNode(true));\n\n let hasResponsiveSvg = false;\n let hasFixedSvg = false;\n\n shadowRoot.querySelectorAll(\"svg\").forEach((svgEl) => {\n // Derive responsive sizing from viewBox so pure viewBox SVGs stay visible and fluid\n const viewBox = svgEl.getAttribute(\"viewBox\");\n if (!viewBox) return;\n\n const dimensions = viewBox\n .trim()\n .split(/[\\s,]+/)\n .map((value) => Number(value));\n\n if (dimensions.length !== 4 || dimensions.some(Number.isNaN)) return;\n\n const [, , viewBoxWidth, viewBoxHeight] = dimensions;\n const widthAttr = svgEl.getAttribute(\"width\");\n const heightAttr = svgEl.getAttribute(\"height\");\n const isRelativeLength = (value?: string | null) => {\n if (!value) return false;\n const normalized = value.trim().toLowerCase();\n return normalized === \"auto\" || normalized.endsWith(\"%\");\n };\n const toNumericLength = (value?: string | null) => {\n if (!value) return null;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"auto\" || normalized.endsWith(\"%\")) {\n return null;\n }\n const parsed = Number.parseFloat(normalized);\n return Number.isNaN(parsed) ? null : parsed;\n };\n // Treat percentage/auto sizing as responsive so viewBox drives the layout\n const isWidthRelative = isRelativeLength(widthAttr);\n const isHeightRelative = isRelativeLength(heightAttr);\n const widthMissing = !widthAttr || widthAttr === \"0\";\n const heightMissing = !heightAttr || heightAttr === \"0\";\n const numericWidth = toNumericLength(widthAttr);\n const numericHeight = toNumericLength(heightAttr);\n const matchesViewBox =\n numericWidth === viewBoxWidth && numericHeight === viewBoxHeight;\n\n // Prefer responsive layout when sizing is relative or matches the viewBox\n const shouldUseResponsiveSize =\n isWidthRelative ||\n isHeightRelative ||\n (widthMissing && heightMissing) ||\n matchesViewBox;\n\n if (shouldUseResponsiveSize) {\n hasResponsiveSvg = true;\n svgEl.classList.add(\"content-render-svg-el--responsive\");\n svgEl.classList.remove(\"content-render-svg-el--fixed\");\n svgEl.style.width = \"100%\";\n svgEl.style.height = \"auto\";\n if (!svgEl.style.aspectRatio && viewBoxHeight > 0) {\n svgEl.style.aspectRatio = `${viewBoxWidth} / ${viewBoxHeight}`;\n }\n return;\n }\n\n hasFixedSvg = true;\n svgEl.classList.add(\"content-render-svg-el--fixed\");\n svgEl.classList.remove(\"content-render-svg-el--responsive\");\n if (widthMissing && viewBoxWidth > 0) {\n svgEl.setAttribute(\"width\", `${viewBoxWidth}`);\n }\n if (heightMissing && viewBoxHeight > 0) {\n svgEl.setAttribute(\"height\", `${viewBoxHeight}`);\n }\n });\n\n const hostResponsive = hasResponsiveSvg && !hasFixedSvg;\n host.classList.toggle(\"content-render-svg--responsive\", hostResponsive);\n host.classList.toggle(\"content-render-svg--fixed\", !hostResponsive);\n }, [svg]);\n\n return (\n <div className=\"content-render-svg-scroll\">\n <div className=\"content-render-svg\" ref={hostRef} />\n </div>\n );\n};\n\n// Extended component interface\ntype CustomComponents = ComponentsWithCustomVariable & {\n \"custom-button-after-content\"?: React.ComponentType<{\n children: React.ReactNode;\n }>;\n};\n\nconst remarkPlugins = [remarkGfm, remarkMath, remarkFlow, remarkBreaks];\n\nconst rehypePlugins = [\n preserveCustomVariableProperties,\n rehypeRaw,\n sanitizeInvalidTagName,\n restoreCustomVariableProperties,\n [rehypeHighlight, { languages: highlightLanguages, subset: subsetLanguages }],\n rehypeKatex,\n];\n\nexport const MarkdownRenderer: React.FC<{\n content: string;\n components: CustomComponents;\n}> = ({ content: markdownContent, components }) => (\n <div className=\"markdown-renderer\">\n <ReactMarkdown\n remarkPlugins={remarkPlugins}\n rehypePlugins={rehypePlugins}\n components={components}\n >\n {markdownContent}\n </ReactMarkdown>\n </div>\n);\n\nconst mergeNonSandboxSegments = (segments: RenderSegment[]) => {\n if (segments.length <= 1) return segments;\n const merged: RenderSegment[] = [];\n\n segments.forEach((segment) => {\n if (segment.type === \"sandbox\") {\n merged.push(segment);\n return;\n }\n\n const last = merged[merged.length - 1];\n if (last && last.type !== \"sandbox\") {\n merged[merged.length - 1] = {\n type: \"markdown\",\n value: `${last.value}${segment.value}`,\n };\n return;\n }\n\n merged.push({ type: \"markdown\", value: segment.value });\n });\n\n return merged;\n};\n\nconst ContentRender: React.FC<ContentRenderProps> = ({\n content,\n customRenderBar,\n onSend,\n typingSpeed = 30,\n enableTypewriter = false,\n userInput,\n interactionDefaultValueOptions,\n defaultButtonText,\n defaultInputText,\n defaultSelectedValues,\n readonly = false,\n onTypeFinished,\n confirmButtonText,\n copyButtonText,\n copiedButtonText,\n sandboxLoadingText,\n sandboxStyleLoadingText,\n sandboxScriptLoadingText,\n sandboxFullscreenButtonText,\n sandboxMode = \"content\",\n onClickCustomButtonAfterContent,\n beforeSend,\n // tooltipMinLength,\n}) => {\n const normalizedContent = useMemo(\n () => normalizeInlineHtml(content),\n [content]\n );\n\n const interactionDefaults = useMemo(\n () =>\n getInteractionDefaultValues(\n content,\n userInput,\n interactionDefaultValueOptions\n ),\n [content, interactionDefaultValueOptions, userInput]\n );\n\n const resolvedDefaultButtonText =\n defaultButtonText?.trim() || interactionDefaults.buttonText;\n const resolvedDefaultInputText =\n defaultInputText?.trim() || interactionDefaults.inputText;\n const fallbackSelectedValues = useMemo(\n () =>\n userInput\n ? userInput\n .split(\",\")\n .map((value) => value.trim())\n .filter(Boolean)\n : undefined,\n [userInput]\n );\n const resolvedDefaultSelectedValues = defaultSelectedValues?.length\n ? defaultSelectedValues\n : interactionDefaults.selectedValues || fallbackSelectedValues;\n\n // Use custom Hook to handle typewriter effect\n const components: CustomComponents = {\n \"custom-button-after-content\": ({\n children,\n }: {\n children: React.ReactNode;\n }) => {\n return (\n <button\n className=\"content-render-custom-button-after-content\"\n onClick={onClickCustomButtonAfterContent}\n >\n <span className=\"content-render-custom-button-after-content-inner\">\n {children}\n </span>\n </button>\n );\n },\n \"custom-variable\": (props) => (\n <CustomButtonInputVariable\n {...props}\n readonly={readonly}\n defaultButtonText={resolvedDefaultButtonText}\n defaultInputText={resolvedDefaultInputText}\n defaultSelectedValues={resolvedDefaultSelectedValues}\n onSend={onSend}\n beforeSend={beforeSend}\n confirmButtonText={confirmButtonText}\n // tooltipMinLength={tooltipMinLength}\n />\n ),\n code: (props) => {\n const { className, children, ...rest } = props as {\n className?: string;\n children?: React.ReactNode;\n };\n const match = /language-(\\w+)/.exec(className || \"\");\n const language = match?.[1];\n if (language === \"mermaid\") {\n const chartContent = children?.toString().replace(/\\n$/, \"\") || \"\";\n const frozen = mermaidBlockIsComplete(content, chartContent);\n return <MermaidChart chart={chartContent} frozen={frozen} />;\n }\n\n return (\n <code className={className} {...rest}>\n {children}\n </code>\n );\n },\n table: ({ ...props }) => (\n <div className=\"content-render-table-container\">\n <table className=\"content-render-table\" {...props} />\n </div>\n ),\n th: ({ ...props }) => <th className=\"content-render-th\" {...props} />,\n td: ({ ...props }) => <td className=\"content-render-td\" {...props} />,\n tr: ({ ...props }) => <tr className=\"content-render-tr\" {...props} />,\n li: ({ node, ...props }) => {\n const className = node?.properties?.className;\n const hasTaskListItem =\n (typeof className === \"string\" &&\n className.includes(\"task-list-item\")) ||\n (Array.isArray(className) && className.includes(\"task-list-item\"));\n if (hasTaskListItem) {\n return <li className=\"content-render-task-list-item\" {...props} />;\n }\n return <li {...props} />;\n },\n ol: ({ ...props }) => <ol className=\"content-render-ol\" {...props} />,\n ul: ({ ...props }) => <ul className=\"content-render-ul\" {...props} />,\n input: ({ ...props }) => {\n if (props.type === \"checkbox\") {\n return (\n <input\n type=\"checkbox\"\n className=\"content-render-checkbox\"\n disabled\n {...props}\n />\n );\n }\n return <input {...props} />;\n },\n a: ({ children, ...props }) => (\n <a target=\"_blank\" rel=\"noopener noreferrer\" {...props}>\n {children}\n </a>\n ),\n pre: (props) => (\n <CodeBlock\n {...props}\n copyButtonText={copyButtonText}\n copiedButtonText={copiedButtonText}\n />\n ),\n };\n\n const { displayContent, isComplete } = useTypewriterStateMachine({\n // processMarkdownText will let code block printf(\"You win!\\n\") become printf(\"You win!<br/>\");\n // content: processMarkdownText(content),\n content: normalizedContent,\n typingSpeed,\n disabled: !enableTypewriter,\n });\n // Render the full content synchronously when typewriter is disabled\n // to avoid a first-paint flash where content appears after helper actions.\n const resolvedDisplayContent = enableTypewriter\n ? displayContent\n : normalizedContent;\n\n const hasPotentialSandboxTags = useMemo(\n () => SANDBOX_TAG_HINT_PATTERN.test(content),\n [content]\n );\n\n const renderSegments = useMemo(\n () => (hasPotentialSandboxTags ? splitContentSegments(content, true) : []),\n [content, hasPotentialSandboxTags]\n );\n\n const hasSandbox = renderSegments.some(\n (segment) => segment.type === \"sandbox\"\n );\n const mergedRenderSegments = useMemo(\n () => mergeNonSandboxSegments(renderSegments),\n [renderSegments]\n );\n\n const segments = useMemo(\n () => parseMarkdownSegments(resolvedDisplayContent),\n [resolvedDisplayContent]\n );\n\n const hasCompleted = useRef(false);\n\n useEffect(() => {\n if (hasSandbox) return;\n if (isComplete && !hasCompleted.current) {\n hasCompleted.current = true; // Mark as completed\n onTypeFinished?.(); // Call the passed callback\n }\n }, [hasSandbox, isComplete, onTypeFinished]);\n\n useEffect(() => {\n if (hasSandbox) return;\n hasCompleted.current = false; // Reset completion status when content changes\n }, [hasSandbox, content]);\n\n const renderMarkdownSegments = (raw: string, keyPrefix: string) => {\n const normalized = normalizeInlineHtml(raw);\n const parsed = parseMarkdownSegments(normalized);\n\n return parsed.map((seg, index) => {\n const key = `${keyPrefix}-${seg.type}-${index}`;\n\n if (seg.type === \"text\") {\n return (\n <MarkdownRenderer\n key={key}\n components={components}\n content={seg.value}\n />\n );\n }\n\n if (seg.type === \"mermaid\") {\n return (\n <MermaidChart key={key} chart={seg.value} frozen={!seg.complete} />\n );\n }\n\n if (seg.type === \"svg\") {\n return <SvgBlockInShadow key={key} svg={seg.value} />;\n }\n\n return null;\n });\n };\n\n if (hasSandbox) {\n return (\n <div className=\"content-render markdown-body\">\n {mergedRenderSegments.map((segment, idx) =>\n segment.type === \"sandbox\" ? (\n <IframeSandbox\n key={`sandbox-${idx}`}\n hideFullScreen\n type=\"sandbox\"\n content={segment.value}\n className=\"content-render-iframe\"\n loadingText={sandboxLoadingText}\n styleLoadingText={sandboxStyleLoadingText}\n scriptLoadingText={sandboxScriptLoadingText}\n fullScreenButtonText={sandboxFullscreenButtonText}\n mode={sandboxMode}\n />\n ) : (\n <React.Fragment key={`md-${idx}`}>\n {renderMarkdownSegments(segment.value, `md-${idx}`)}\n </React.Fragment>\n )\n )}\n </div>\n );\n }\n\n return (\n <div className=\"content-render markdown-body\">\n {segments.map((seg, index) => {\n if (seg.type === \"text\") {\n return (\n <MarkdownRenderer\n key={index}\n components={components}\n content={seg.value}\n />\n );\n }\n\n if (seg.type === \"mermaid\") {\n return (\n <MermaidChart\n key={index}\n chart={seg.value}\n frozen={!seg.complete}\n />\n );\n }\n\n if (seg.type === \"svg\") {\n return <SvgBlockInShadow key={index} svg={seg.value} />;\n }\n })}\n\n {customRenderBar && (\n <div className=\"content-render-custom-bar\">\n {React.createElement(customRenderBar, {\n content,\n displayContent,\n onSend,\n })}\n </div>\n )}\n </div>\n );\n};\n\nexport default ContentRender;\n"],"names":["SANDBOX_TAG_HINT_PATTERN","SvgBlockInShadow","svg","hostRef","useRef","useEffect","host","shadowRoot","styleId","styleEl","node","template","cleanedSvg","stripSvgTextLineBreaks","hasResponsiveSvg","hasFixedSvg","svgEl","viewBox","dimensions","value","viewBoxWidth","viewBoxHeight","widthAttr","heightAttr","isRelativeLength","normalized","toNumericLength","parsed","isWidthRelative","isHeightRelative","widthMissing","heightMissing","numericWidth","numericHeight","hostResponsive","jsx","remarkPlugins","remarkGfm","remarkMath","remarkFlow","remarkBreaks","rehypePlugins","preserveCustomVariableProperties","rehypeRaw","sanitizeInvalidTagName","restoreCustomVariableProperties","rehypeHighlight","highlightLanguages","subsetLanguages","rehypeKatex","MarkdownRenderer","markdownContent","components","ReactMarkdown","mergeNonSandboxSegments","segments","merged","segment","last","ContentRender","content","customRenderBar","onSend","typingSpeed","enableTypewriter","userInput","interactionDefaultValueOptions","defaultButtonText","defaultInputText","defaultSelectedValues","readonly","onTypeFinished","confirmButtonText","copyButtonText","copiedButtonText","sandboxLoadingText","sandboxStyleLoadingText","sandboxScriptLoadingText","sandboxFullscreenButtonText","sandboxMode","onClickCustomButtonAfterContent","beforeSend","normalizedContent","useMemo","normalizeInlineHtml","interactionDefaults","getInteractionDefaultValues","resolvedDefaultButtonText","resolvedDefaultInputText","fallbackSelectedValues","resolvedDefaultSelectedValues","children","props","CustomButtonInputVariable","className","rest","chartContent","frozen","mermaidBlockIsComplete","MermaidChart","CodeBlock","displayContent","isComplete","useTypewriterStateMachine","resolvedDisplayContent","hasPotentialSandboxTags","renderSegments","splitContentSegments","hasSandbox","mergedRenderSegments","parseMarkdownSegments","hasCompleted","renderMarkdownSegments","raw","keyPrefix","seg","index","key","idx","IframeSandbox","React","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAMA,KACJ,mGAkDIC,IAA8C,CAAC,EAAE,KAAAC,QAAU;AAC/D,QAAMC,IAAUC,EAAuB,IAAI;AAE3C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAQ;AACrB,QAAI,CAACG,EAAM;AACX,UAAMC,IAAaD,EAAK,cAAcA,EAAK,aAAa,EAAE,MAAM,QAAQ,GAClEE,IAAU;AAChB,QAAIC,IAAUF,EAAW,eAAeC,CAAO;AAE/C,IAAKC,MACHA,IAAU,SAAS,cAAc,OAAO,GACxCA,EAAQ,KAAKD,GAEbC,EAAQ,cAAc;AAAA;AAAA;AAAA;AAAA,SAKtBF,EAAW,YAAYE,CAAO,IAGV,MAAM,KAAKF,EAAW,UAAU,EAAE;AAAA,MACtD,CAACG,MAASA,MAASD;AAAA,IAAA,EAEP,QAAQ,CAACC,MAASH,EAAW,YAAYG,CAAI,CAAC;AAE5D,UAAMC,IAAW,SAAS,cAAc,UAAU,GAC5CC,IAAaC,GAAuBX,CAAG;AAC7C,IAAAS,EAAS,YAAYC,GACrBL,EAAW,OAAOI,EAAS,QAAQ,UAAU,EAAI,CAAC;AA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D/B,MAAMA,CAAG,EAE9B;AAAA,EAAA,GAGN,IAKFG,gBAAAA,EAAAA,KAAC,OAAA,EAAI,WAAU,gCACZ,UAAA;AAAA,IAAAlE,GAAS,IAAI,CAAC4D,GAAKC,MAAU;AAC5B,UAAID,EAAI,SAAS;AACf,eACEhF,gBAAAA,EAAAA;AAAAA,UAACe;AAAA,UAAA;AAAA,YAEC,YAAAE;AAAA,YACA,SAAS+D,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eACEhF,gBAAAA,EAAAA;AAAAA,UAACgE;AAAA,UAAA;AAAA,YAEC,OAAOgB,EAAI;AAAA,YACX,QAAQ,CAACA,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eAAOhF,gBAAAA,EAAAA,IAAClC,GAAA,EAA6B,KAAKkH,EAAI,SAAhBC,CAAuB;AAAA,IAEzD,CAAC;AAAA,IAEAvD,KACC1B,gBAAAA,EAAAA,IAAC,OAAA,EAAI,WAAU,6BACZ,UAAAqF,EAAM,cAAc3D,GAAiB;AAAA,MACpC,SAAAD;AAAA,MACA,gBAAAyC;AAAA,MACA,QAAAvC;AAAA,IAAA,CACD,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"ContentRender.es.js","sources":["../../../src/components/ContentRender/ContentRender.tsx"],"sourcesContent":["import \"highlight.js/styles/github.css\";\nimport \"katex/dist/katex.min.css\";\nimport React, { useEffect, useMemo, useRef } from \"react\";\nimport ReactMarkdown from \"react-markdown\";\nimport rehypeHighlight from \"rehype-highlight\";\nimport rehypeKatex from \"rehype-katex\";\nimport rehypeRaw from \"rehype-raw\";\nimport remarkBreaks from \"remark-breaks\";\nimport remarkFlow from \"remark-flow\";\nimport remarkGfm from \"remark-gfm\";\nimport remarkMath from \"remark-math\";\nimport { CustomRenderBarProps, OnSendContentParams } from \"../types\";\nimport { sanitizeInvalidTagName } from \"./utils/sanitize-invalid-tag-name\";\nimport { stripSvgTextLineBreaks } from \"./utils/strip-svg-text-line-breaks\";\nimport \"./contentRender.css\";\nimport \"./github-markdown-light.css\";\nimport CodeBlock from \"./CodeBlock\";\nimport CustomButtonInputVariable, {\n ComponentsWithCustomVariable,\n} from \"./plugins/CustomVariable\";\nimport MermaidChart from \"./plugins/MermaidChart\";\nimport useTypewriterStateMachine from \"./useTypewriterStateMachine\";\nimport {\n preserveCustomVariableProperties,\n restoreCustomVariableProperties,\n} from \"./utils/custom-variable-props\";\nimport {\n highlightLanguages,\n subsetLanguages,\n} from \"./utils/highlight-languages\";\n// import { processMarkdownText } from \"./utils/process-markdown\";\nimport {\n parseMarkdownSegments,\n mermaidBlockIsComplete,\n} from \"./utils/mermaid-parse\";\nimport { normalizeInlineHtml } from \"./utils/normalize-inline-html\";\nimport IframeSandbox from \"./IframeSandbox\";\nimport {\n splitContentSegments,\n type RenderSegment,\n} from \"./utils/split-content\";\nimport {\n getInteractionDefaultValues,\n type InteractionDefaultValueOptions,\n} from \"../../lib/interaction-defaults\";\n\nconst SANDBOX_TAG_HINT_PATTERN =\n /<(script|style|link|iframe|html|head|body|meta|title|base|template|div|section|article|main)\\b/i;\n// Define component Props type\nexport interface ContentRenderProps {\n content: string;\n /**\n * Callback invoked when the custom button after content is clicked.\n * This button is rendered via the `<custom-button-after-content>` tag in markdown content.\n * @example\n * ```tsx\n * <ContentRender\n * content=\"Hello <custom-button-after-content>Ask</custom-button-after-content>\"\n * onClickCustomButtonAfterContent={() => console.log('Button clicked')}\n * />\n * ```\n */\n customRenderBar?: CustomRenderBarProps;\n onClickCustomButtonAfterContent?: () => void;\n onSend?: (content: OnSendContentParams) => void;\n typingSpeed?: number;\n enableTypewriter?: boolean;\n userInput?: string;\n interactionDefaultValueOptions?: InteractionDefaultValueOptions;\n defaultButtonText?: string;\n defaultInputText?: string; // Text input by user\n defaultSelectedValues?: string[]; // Default selected values for multi-select\n readonly?: boolean;\n onTypeFinished?: () => void;\n // Multi-select confirm button text (i18n support)\n confirmButtonText?: string;\n // Copy button text (i18n support)\n copyButtonText?: string;\n // Copied state text (i18n support)\n copiedButtonText?: string;\n // Dynamic interaction format for multi-select support\n dynamicInteractionFormat?: string;\n // Loading text before first HTML block renders inside iframe (i18n support)\n sandboxLoadingText?: string;\n // Loading text while styles are being generated inside iframe\n sandboxStyleLoadingText?: string;\n // Loading text while scripts are being cached/executed inside iframe\n sandboxScriptLoadingText?: string;\n // Disable sandbox loading overlays when upper layers have already entered an error state\n disableSandboxLoadingOverlay?: boolean;\n // Fullscreen button text for iframe sandbox\n sandboxFullscreenButtonText?: string;\n // Sandbox render mode\n sandboxMode?: \"content\" | \"blackboard\";\n beforeSend?: (param: OnSendContentParams) => boolean;\n // tooltipMinLength?: number; // Control minimum character length for tooltip display, default 10\n}\n\n// Render svg string via Shadow DOM to avoid markdown wrapping\nconst SvgBlockInShadow: React.FC<{ svg: string }> = ({ svg }) => {\n const hostRef = useRef<HTMLDivElement>(null);\n\n useEffect(() => {\n const host = hostRef.current;\n if (!host) return;\n const shadowRoot = host.shadowRoot ?? host.attachShadow({ mode: \"open\" });\n const styleId = \"content-render-svg-style\";\n let styleEl = shadowRoot.getElementById(styleId) as HTMLStyleElement | null;\n\n if (!styleEl) {\n styleEl = document.createElement(\"style\");\n styleEl.id = styleId;\n // Keep intrinsic SVG width so the wrapper can scroll horizontally when needed\n styleEl.textContent = `\n svg { height: auto; display: inline-block; }\n svg.content-render-svg-el--responsive { width: 100%; max-width: 100%; }\n svg.content-render-svg-el--fixed { max-width: none; }\n `;\n shadowRoot.appendChild(styleEl);\n }\n\n const nodesToRemove = Array.from(shadowRoot.childNodes).filter(\n (node) => node !== styleEl\n );\n nodesToRemove.forEach((node) => shadowRoot.removeChild(node));\n\n const template = document.createElement(\"template\");\n const cleanedSvg = stripSvgTextLineBreaks(svg);\n template.innerHTML = cleanedSvg;\n shadowRoot.append(template.content.cloneNode(true));\n\n let hasResponsiveSvg = false;\n let hasFixedSvg = false;\n\n shadowRoot.querySelectorAll(\"svg\").forEach((svgEl) => {\n // Derive responsive sizing from viewBox so pure viewBox SVGs stay visible and fluid\n const viewBox = svgEl.getAttribute(\"viewBox\");\n if (!viewBox) return;\n\n const dimensions = viewBox\n .trim()\n .split(/[\\s,]+/)\n .map((value) => Number(value));\n\n if (dimensions.length !== 4 || dimensions.some(Number.isNaN)) return;\n\n const [, , viewBoxWidth, viewBoxHeight] = dimensions;\n const widthAttr = svgEl.getAttribute(\"width\");\n const heightAttr = svgEl.getAttribute(\"height\");\n const isRelativeLength = (value?: string | null) => {\n if (!value) return false;\n const normalized = value.trim().toLowerCase();\n return normalized === \"auto\" || normalized.endsWith(\"%\");\n };\n const toNumericLength = (value?: string | null) => {\n if (!value) return null;\n const normalized = value.trim().toLowerCase();\n if (normalized === \"auto\" || normalized.endsWith(\"%\")) {\n return null;\n }\n const parsed = Number.parseFloat(normalized);\n return Number.isNaN(parsed) ? null : parsed;\n };\n // Treat percentage/auto sizing as responsive so viewBox drives the layout\n const isWidthRelative = isRelativeLength(widthAttr);\n const isHeightRelative = isRelativeLength(heightAttr);\n const widthMissing = !widthAttr || widthAttr === \"0\";\n const heightMissing = !heightAttr || heightAttr === \"0\";\n const numericWidth = toNumericLength(widthAttr);\n const numericHeight = toNumericLength(heightAttr);\n const matchesViewBox =\n numericWidth === viewBoxWidth && numericHeight === viewBoxHeight;\n\n // Prefer responsive layout when sizing is relative or matches the viewBox\n const shouldUseResponsiveSize =\n isWidthRelative ||\n isHeightRelative ||\n (widthMissing && heightMissing) ||\n matchesViewBox;\n\n if (shouldUseResponsiveSize) {\n hasResponsiveSvg = true;\n svgEl.classList.add(\"content-render-svg-el--responsive\");\n svgEl.classList.remove(\"content-render-svg-el--fixed\");\n svgEl.style.width = \"100%\";\n svgEl.style.height = \"auto\";\n if (!svgEl.style.aspectRatio && viewBoxHeight > 0) {\n svgEl.style.aspectRatio = `${viewBoxWidth} / ${viewBoxHeight}`;\n }\n return;\n }\n\n hasFixedSvg = true;\n svgEl.classList.add(\"content-render-svg-el--fixed\");\n svgEl.classList.remove(\"content-render-svg-el--responsive\");\n if (widthMissing && viewBoxWidth > 0) {\n svgEl.setAttribute(\"width\", `${viewBoxWidth}`);\n }\n if (heightMissing && viewBoxHeight > 0) {\n svgEl.setAttribute(\"height\", `${viewBoxHeight}`);\n }\n });\n\n const hostResponsive = hasResponsiveSvg && !hasFixedSvg;\n host.classList.toggle(\"content-render-svg--responsive\", hostResponsive);\n host.classList.toggle(\"content-render-svg--fixed\", !hostResponsive);\n }, [svg]);\n\n return (\n <div className=\"content-render-svg-scroll\">\n <div className=\"content-render-svg\" ref={hostRef} />\n </div>\n );\n};\n\n// Extended component interface\ntype CustomComponents = ComponentsWithCustomVariable & {\n \"custom-button-after-content\"?: React.ComponentType<{\n children: React.ReactNode;\n }>;\n};\n\nconst remarkPlugins = [remarkGfm, remarkMath, remarkFlow, remarkBreaks];\n\nconst rehypePlugins = [\n preserveCustomVariableProperties,\n rehypeRaw,\n sanitizeInvalidTagName,\n restoreCustomVariableProperties,\n [rehypeHighlight, { languages: highlightLanguages, subset: subsetLanguages }],\n rehypeKatex,\n];\n\nexport const MarkdownRenderer: React.FC<{\n content: string;\n components: CustomComponents;\n}> = ({ content: markdownContent, components }) => (\n <div className=\"markdown-renderer\">\n <ReactMarkdown\n remarkPlugins={remarkPlugins}\n rehypePlugins={rehypePlugins}\n components={components}\n >\n {markdownContent}\n </ReactMarkdown>\n </div>\n);\n\nconst mergeNonSandboxSegments = (segments: RenderSegment[]) => {\n if (segments.length <= 1) return segments;\n const merged: RenderSegment[] = [];\n\n segments.forEach((segment) => {\n if (segment.type === \"sandbox\") {\n merged.push(segment);\n return;\n }\n\n const last = merged[merged.length - 1];\n if (last && last.type !== \"sandbox\") {\n merged[merged.length - 1] = {\n type: \"markdown\",\n value: `${last.value}${segment.value}`,\n };\n return;\n }\n\n merged.push({ type: \"markdown\", value: segment.value });\n });\n\n return merged;\n};\n\nconst ContentRender: React.FC<ContentRenderProps> = ({\n content,\n customRenderBar,\n onSend,\n typingSpeed = 30,\n enableTypewriter = false,\n userInput,\n interactionDefaultValueOptions,\n defaultButtonText,\n defaultInputText,\n defaultSelectedValues,\n readonly = false,\n onTypeFinished,\n confirmButtonText,\n copyButtonText,\n copiedButtonText,\n sandboxLoadingText,\n sandboxStyleLoadingText,\n sandboxScriptLoadingText,\n disableSandboxLoadingOverlay = false,\n sandboxFullscreenButtonText,\n sandboxMode = \"content\",\n onClickCustomButtonAfterContent,\n beforeSend,\n // tooltipMinLength,\n}) => {\n const normalizedContent = useMemo(\n () => normalizeInlineHtml(content),\n [content]\n );\n\n const interactionDefaults = useMemo(\n () =>\n getInteractionDefaultValues(\n content,\n userInput,\n interactionDefaultValueOptions\n ),\n [content, interactionDefaultValueOptions, userInput]\n );\n\n const resolvedDefaultButtonText =\n defaultButtonText?.trim() || interactionDefaults.buttonText;\n const resolvedDefaultInputText =\n defaultInputText?.trim() || interactionDefaults.inputText;\n const fallbackSelectedValues = useMemo(\n () =>\n userInput\n ? userInput\n .split(\",\")\n .map((value) => value.trim())\n .filter(Boolean)\n : undefined,\n [userInput]\n );\n const resolvedDefaultSelectedValues = defaultSelectedValues?.length\n ? defaultSelectedValues\n : interactionDefaults.selectedValues || fallbackSelectedValues;\n\n // Use custom Hook to handle typewriter effect\n const components: CustomComponents = {\n \"custom-button-after-content\": ({\n children,\n }: {\n children: React.ReactNode;\n }) => {\n return (\n <button\n className=\"content-render-custom-button-after-content\"\n onClick={onClickCustomButtonAfterContent}\n >\n <span className=\"content-render-custom-button-after-content-inner\">\n {children}\n </span>\n </button>\n );\n },\n \"custom-variable\": (props) => (\n <CustomButtonInputVariable\n {...props}\n readonly={readonly}\n defaultButtonText={resolvedDefaultButtonText}\n defaultInputText={resolvedDefaultInputText}\n defaultSelectedValues={resolvedDefaultSelectedValues}\n onSend={onSend}\n beforeSend={beforeSend}\n confirmButtonText={confirmButtonText}\n // tooltipMinLength={tooltipMinLength}\n />\n ),\n code: (props) => {\n const { className, children, ...rest } = props as {\n className?: string;\n children?: React.ReactNode;\n };\n const match = /language-(\\w+)/.exec(className || \"\");\n const language = match?.[1];\n if (language === \"mermaid\") {\n const chartContent = children?.toString().replace(/\\n$/, \"\") || \"\";\n const frozen = mermaidBlockIsComplete(content, chartContent);\n return <MermaidChart chart={chartContent} frozen={frozen} />;\n }\n\n return (\n <code className={className} {...rest}>\n {children}\n </code>\n );\n },\n table: ({ ...props }) => (\n <div className=\"content-render-table-container\">\n <table className=\"content-render-table\" {...props} />\n </div>\n ),\n th: ({ ...props }) => <th className=\"content-render-th\" {...props} />,\n td: ({ ...props }) => <td className=\"content-render-td\" {...props} />,\n tr: ({ ...props }) => <tr className=\"content-render-tr\" {...props} />,\n li: ({ node, ...props }) => {\n const className = node?.properties?.className;\n const hasTaskListItem =\n (typeof className === \"string\" &&\n className.includes(\"task-list-item\")) ||\n (Array.isArray(className) && className.includes(\"task-list-item\"));\n if (hasTaskListItem) {\n return <li className=\"content-render-task-list-item\" {...props} />;\n }\n return <li {...props} />;\n },\n ol: ({ ...props }) => <ol className=\"content-render-ol\" {...props} />,\n ul: ({ ...props }) => <ul className=\"content-render-ul\" {...props} />,\n input: ({ ...props }) => {\n if (props.type === \"checkbox\") {\n return (\n <input\n type=\"checkbox\"\n className=\"content-render-checkbox\"\n disabled\n {...props}\n />\n );\n }\n return <input {...props} />;\n },\n a: ({ children, ...props }) => (\n <a target=\"_blank\" rel=\"noopener noreferrer\" {...props}>\n {children}\n </a>\n ),\n pre: (props) => (\n <CodeBlock\n {...props}\n copyButtonText={copyButtonText}\n copiedButtonText={copiedButtonText}\n />\n ),\n };\n\n const { displayContent, isComplete } = useTypewriterStateMachine({\n // processMarkdownText will let code block printf(\"You win!\\n\") become printf(\"You win!<br/>\");\n // content: processMarkdownText(content),\n content: normalizedContent,\n typingSpeed,\n disabled: !enableTypewriter,\n });\n // Render the full content synchronously when typewriter is disabled\n // to avoid a first-paint flash where content appears after helper actions.\n const resolvedDisplayContent = enableTypewriter\n ? displayContent\n : normalizedContent;\n\n const hasPotentialSandboxTags = useMemo(\n () => SANDBOX_TAG_HINT_PATTERN.test(content),\n [content]\n );\n\n const renderSegments = useMemo(\n () => (hasPotentialSandboxTags ? splitContentSegments(content, true) : []),\n [content, hasPotentialSandboxTags]\n );\n\n const hasSandbox = renderSegments.some(\n (segment) => segment.type === \"sandbox\"\n );\n const mergedRenderSegments = useMemo(\n () => mergeNonSandboxSegments(renderSegments),\n [renderSegments]\n );\n\n const segments = useMemo(\n () => parseMarkdownSegments(resolvedDisplayContent),\n [resolvedDisplayContent]\n );\n\n const hasCompleted = useRef(false);\n\n useEffect(() => {\n if (hasSandbox) return;\n if (isComplete && !hasCompleted.current) {\n hasCompleted.current = true; // Mark as completed\n onTypeFinished?.(); // Call the passed callback\n }\n }, [hasSandbox, isComplete, onTypeFinished]);\n\n useEffect(() => {\n if (hasSandbox) return;\n hasCompleted.current = false; // Reset completion status when content changes\n }, [hasSandbox, content]);\n\n const renderMarkdownSegments = (raw: string, keyPrefix: string) => {\n const normalized = normalizeInlineHtml(raw);\n const parsed = parseMarkdownSegments(normalized);\n\n return parsed.map((seg, index) => {\n const key = `${keyPrefix}-${seg.type}-${index}`;\n\n if (seg.type === \"text\") {\n return (\n <MarkdownRenderer\n key={key}\n components={components}\n content={seg.value}\n />\n );\n }\n\n if (seg.type === \"mermaid\") {\n return (\n <MermaidChart key={key} chart={seg.value} frozen={!seg.complete} />\n );\n }\n\n if (seg.type === \"svg\") {\n return <SvgBlockInShadow key={key} svg={seg.value} />;\n }\n\n return null;\n });\n };\n\n if (hasSandbox) {\n return (\n <div className=\"content-render markdown-body\">\n {mergedRenderSegments.map((segment, idx) =>\n segment.type === \"sandbox\" ? (\n <IframeSandbox\n key={`sandbox-${idx}`}\n hideFullScreen\n type=\"sandbox\"\n content={segment.value}\n className=\"content-render-iframe\"\n loadingText={sandboxLoadingText}\n styleLoadingText={sandboxStyleLoadingText}\n scriptLoadingText={sandboxScriptLoadingText}\n disableLoadingOverlay={disableSandboxLoadingOverlay}\n fullScreenButtonText={sandboxFullscreenButtonText}\n mode={sandboxMode}\n />\n ) : (\n <React.Fragment key={`md-${idx}`}>\n {renderMarkdownSegments(segment.value, `md-${idx}`)}\n </React.Fragment>\n )\n )}\n </div>\n );\n }\n\n return (\n <div className=\"content-render markdown-body\">\n {segments.map((seg, index) => {\n if (seg.type === \"text\") {\n return (\n <MarkdownRenderer\n key={index}\n components={components}\n content={seg.value}\n />\n );\n }\n\n if (seg.type === \"mermaid\") {\n return (\n <MermaidChart\n key={index}\n chart={seg.value}\n frozen={!seg.complete}\n />\n );\n }\n\n if (seg.type === \"svg\") {\n return <SvgBlockInShadow key={index} svg={seg.value} />;\n }\n })}\n\n {customRenderBar && (\n <div className=\"content-render-custom-bar\">\n {React.createElement(customRenderBar, {\n content,\n displayContent,\n onSend,\n })}\n </div>\n )}\n </div>\n );\n};\n\nexport default ContentRender;\n"],"names":["SANDBOX_TAG_HINT_PATTERN","SvgBlockInShadow","svg","hostRef","useRef","useEffect","host","shadowRoot","styleId","styleEl","node","template","cleanedSvg","stripSvgTextLineBreaks","hasResponsiveSvg","hasFixedSvg","svgEl","viewBox","dimensions","value","viewBoxWidth","viewBoxHeight","widthAttr","heightAttr","isRelativeLength","normalized","toNumericLength","parsed","isWidthRelative","isHeightRelative","widthMissing","heightMissing","numericWidth","numericHeight","hostResponsive","jsx","remarkPlugins","remarkGfm","remarkMath","remarkFlow","remarkBreaks","rehypePlugins","preserveCustomVariableProperties","rehypeRaw","sanitizeInvalidTagName","restoreCustomVariableProperties","rehypeHighlight","highlightLanguages","subsetLanguages","rehypeKatex","MarkdownRenderer","markdownContent","components","ReactMarkdown","mergeNonSandboxSegments","segments","merged","segment","last","ContentRender","content","customRenderBar","onSend","typingSpeed","enableTypewriter","userInput","interactionDefaultValueOptions","defaultButtonText","defaultInputText","defaultSelectedValues","readonly","onTypeFinished","confirmButtonText","copyButtonText","copiedButtonText","sandboxLoadingText","sandboxStyleLoadingText","sandboxScriptLoadingText","disableSandboxLoadingOverlay","sandboxFullscreenButtonText","sandboxMode","onClickCustomButtonAfterContent","beforeSend","normalizedContent","useMemo","normalizeInlineHtml","interactionDefaults","getInteractionDefaultValues","resolvedDefaultButtonText","resolvedDefaultInputText","fallbackSelectedValues","resolvedDefaultSelectedValues","children","props","CustomButtonInputVariable","className","rest","chartContent","frozen","mermaidBlockIsComplete","MermaidChart","CodeBlock","displayContent","isComplete","useTypewriterStateMachine","resolvedDisplayContent","hasPotentialSandboxTags","renderSegments","splitContentSegments","hasSandbox","mergedRenderSegments","parseMarkdownSegments","hasCompleted","renderMarkdownSegments","raw","keyPrefix","seg","index","key","idx","IframeSandbox","React","jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAMA,KACJ,mGAoDIC,IAA8C,CAAC,EAAE,KAAAC,QAAU;AAC/D,QAAMC,IAAUC,EAAuB,IAAI;AAE3C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAOH,EAAQ;AACrB,QAAI,CAACG,EAAM;AACX,UAAMC,IAAaD,EAAK,cAAcA,EAAK,aAAa,EAAE,MAAM,QAAQ,GAClEE,IAAU;AAChB,QAAIC,IAAUF,EAAW,eAAeC,CAAO;AAE/C,IAAKC,MACHA,IAAU,SAAS,cAAc,OAAO,GACxCA,EAAQ,KAAKD,GAEbC,EAAQ,cAAc;AAAA;AAAA;AAAA;AAAA,SAKtBF,EAAW,YAAYE,CAAO,IAGV,MAAM,KAAKF,EAAW,UAAU,EAAE;AAAA,MACtD,CAACG,MAASA,MAASD;AAAA,IAAA,EAEP,QAAQ,CAACC,MAASH,EAAW,YAAYG,CAAI,CAAC;AAE5D,UAAMC,IAAW,SAAS,cAAc,UAAU,GAC5CC,IAAaC,GAAuBX,CAAG;AAC7C,IAAAS,EAAS,YAAYC,GACrBL,EAAW,OAAOI,EAAS,QAAQ,UAAU,EAAI,CAAC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AAR,GAAuBxD,EAAQ,OAAO,MAAM8D,CAAG,EAAE,EAAA,GAD/B,MAAMA,CAAG,EAE9B;AAAA,EAAA,GAGN,IAKFG,gBAAAA,EAAAA,KAAC,OAAA,EAAI,WAAU,gCACZ,UAAA;AAAA,IAAAnE,GAAS,IAAI,CAAC6D,GAAKC,MAAU;AAC5B,UAAID,EAAI,SAAS;AACf,eACEjF,gBAAAA,EAAAA;AAAAA,UAACe;AAAA,UAAA;AAAA,YAEC,YAAAE;AAAA,YACA,SAASgE,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eACEjF,gBAAAA,EAAAA;AAAAA,UAACiE;AAAA,UAAA;AAAA,YAEC,OAAOgB,EAAI;AAAA,YACX,QAAQ,CAACA,EAAI;AAAA,UAAA;AAAA,UAFRC;AAAA,QAAA;AAOX,UAAID,EAAI,SAAS;AACf,eAAOjF,gBAAAA,EAAAA,IAAClC,GAAA,EAA6B,KAAKmH,EAAI,SAAhBC,CAAuB;AAAA,IAEzD,CAAC;AAAA,IAEAxD,KACC1B,gBAAAA,EAAAA,IAAC,OAAA,EAAI,WAAU,6BACZ,UAAAsF,EAAM,cAAc5D,GAAiB;AAAA,MACpC,SAAAD;AAAA,MACA,gBAAA0C;AAAA,MACA,QAAAxC;AAAA,IAAA,CACD,EAAA,CACH;AAAA,EAAA,GAEJ;AAEJ;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const C=require("../../_virtual/jsx-runtime.cjs.js"),t=require("react"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const C=require("../../_virtual/jsx-runtime.cjs.js"),t=require("react"),Oe=require("react-dom/client"),Ve=require("./SandboxApp.cjs.js"),qe=require("./ContentRender.cjs.js"),E=require("./utils/iframe-viewport-height.cjs.js"),Se=require("../../lib/sandboxInteraction.cjs.js"),Be=require("./utils/iframe-scaling.cjs.js");let ne=null;const We=()=>(ne||(ne=Promise.resolve().then(()=>require("./blackboard-vendor.cjs.js")).then(c=>c.injectBlackboardLibraries)),ne),Pe=/<img\b[^>]*>/i,De=180,$e=240,ze=c=>c.split(/\s+/).filter(Boolean).map(i=>{const s=i.split(":");return s[s.length-1]!=="h-screen"&&s[s.length-1]!=="min-h-screen"?i:(s[s.length-1]="h-full",s.join(":"))}).join(" "),Ge=(c,i)=>!i||!c.trim()?c:c.replace(/^(\s*<[a-zA-Z][\w:-]*)(\s[^>]*?)?>/,(s,O,M="")=>{const d=M.match(/\bclass\s*=\s*(["'])([^"']*)\1/i);if(!d)return s;const V=ze(d[2]);return V===d[2]?s:`${O}${M.replace(d[0],`class=${d[1]}${V}${d[1]}`)}>`}),Le=({content:c,type:i,className:s,styleLoadingText:O,scriptLoadingText:M,fullScreenButtonText:d,hideFullScreen:V=!1,mode:l="content",replaceRootScreenHeightWithFull:ve=!1,enableScaling:ye=!1,disableLoadingOverlay:re=!1})=>{const q=t.useRef(null),f=t.useRef(null),G=t.useRef(null),T=t.useRef(()=>{}),[Ce,Me]=t.useState(480),[oe,Te]=t.useState(0),[L,ie]=t.useState(0),U=t.useRef(!1),Y=t.useRef(!1),se=t.useRef(0),[ce,Ae]=t.useState(0),[X,_e]=t.useState(!1),ke=i==="sandbox",m=l==="blackboard",H=ye&&m&&i==="sandbox",A=m&&i==="sandbox",S=A&&ve,Z=t.useRef(""),B=t.useMemo(()=>i==="sandbox"?c:"",[c,i]),r=t.useMemo(()=>Ge(B,S),[B,S]),le=t.useMemo(()=>S?E.inspectViewportHeightFromHtmlRootString(B):E.EMPTY_ROOT_HEIGHT_META,[B,S]),ue=t.useMemo(()=>S&&le.hasFullViewportHeight,[le.hasFullViewportHeight,S]),[W,ae]=t.useState(r),he=t.useRef(r),J=t.useRef(r),_=t.useRef(null),k=t.useRef(null),de=t.useRef(null),fe=t.useCallback(n=>{if(typeof window>"u")return;const e=Date.now();e-se.current<$e||(se.current=e,window.postMessage({source:Se.SANDBOX_INTERACTION_MESSAGE_SOURCE,type:Se.SANDBOX_INTERACTION_MESSAGE_TYPE,eventType:n},window.location.origin))},[]),K=()=>{_.current!==null&&(window.clearTimeout(_.current),_.current=null)},je=()=>{k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)};t.useEffect(()=>()=>{K(),je()},[]),t.useEffect(()=>{const n=he.current;he.current=r;const e=!!n&&r.length>n.length&&r.startsWith(n),u=Pe.test(r);if(!(e&&u)){K(),J.current=r,ae(r);return}J.current=r,K(),_.current=window.setTimeout(()=>{ae(J.current),_.current=null},De)},[r]);const P=t.useMemo(()=>A?E.inspectViewportHeightFromHtmlRootString(W).viewportHeightCss:null,[W,A]);t.useEffect(()=>{de.current=P},[P]);const me=!!P,j=m&&i==="sandbox"?H||ue?"100%":P??`${Ce}px`:void 0;t.useEffect(()=>{if(l!=="blackboard"){Z.current=r;return}const n=Z.current;!(n&&r.startsWith(n))&&n&&Ae(u=>u+1),Z.current=r},[l,r]),t.useEffect(()=>{const n=f.current;if(!n)return;const e=n.contentDocument;if(!e)return;e.open(),e.write(`<!DOCTYPE html>
|
|
2
2
|
<html${l==="blackboard"?' style="height: 100%;"':""}>
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
@@ -20,5 +20,5 @@
|
|
|
20
20
|
<body>
|
|
21
21
|
<div id="root"></div>
|
|
22
22
|
</body>
|
|
23
|
-
</html>`),e.close(),e.documentElement.setAttribute("data-theme","light"),e.documentElement.style.colorScheme="light",e.body?.style.setProperty("color-scheme","light");const u=m&&i==="sandbox",D=()=>
|
|
23
|
+
</html>`),e.close(),e.documentElement.setAttribute("data-theme","light"),e.documentElement.style.colorScheme="light",e.body?.style.setProperty("color-scheme","light");const u=m&&i==="sandbox",D=()=>fe("click");u&&e.addEventListener("click",D,!0);const F=e.getElementById("root");if(!F)return;const be=Oe.createRoot(F);G.current=be;let I=!1;const pe=o=>({heightAttrValue:o.getAttribute("height"),styleAttrValue:o.getAttribute("style"),classAttrValue:o.getAttribute("class")}),He=o=>{const x=Array.from(o.children);return x.length===1?x[0]:null},Ne=()=>{if(!A||!f.current||!e.body)return null;const o=f.current.ownerDocument?.documentElement?.clientHeight||window.innerHeight,x=de.current,$=x?E.parseExplicitHeight(x,o):null;if($!==null)return Math.ceil($);const h=e.body.querySelector(".sandbox-wrapper")?.firstElementChild;if(!h)return null;const g=Array.from(h.children),w=g.length===1?g[0]:null,a=E.inspectViewportHeightFromNodeChain(w,{getNode:pe,getSingleChild:He}).viewportHeightCss;if(a){const b=E.parseExplicitHeight(a,o);if(b!==null)return Math.ceil(b)}const N=E.resolveExplicitHeightFromNodeChain(w,o,{getNode:pe,getSingleChild:He});return N!==null?Math.ceil(N):null},Q=()=>{if(!f.current||!e.body)return;if(!m){if(U.current){Y.current=!0;return}U.current=!0;const h=f.current,g=q.current?.clientWidth||0,w=h.style.height;if(g>0){const te=Math.round(g*9/16);h.style.height=te+"px",e.body.offsetHeight;let a=e.body.scrollHeight;const N=e.defaultView;if(N){const b=p=>{let y=0;const Re=R=>{if(R!==p&&R.scrollHeight>R.clientHeight+1){const z=N.getComputedStyle(R).overflowY;if(z==="auto"||z==="scroll"){const Ee=R.getBoundingClientRect();Ee.top>=0&&(y=Math.max(y,Math.ceil(Ee.top+R.scrollHeight)))}}for(const z of R.children)Re(z)};return Re(p),y};a=Math.max(a,b(e.body));for(let p=0;p<8&&a>te;p++){h.style.height=a+"px",e.body.offsetHeight;const y=Math.max(e.body.scrollHeight,b(e.body));if(y<=a+1)break;a=y}}h.style.height=w,Te(b=>{const p=Math.max(200,Math.ceil(a));return b===p?b:p})}setTimeout(()=>{U.current=!1,Y.current&&(Y.current=!1,v())},50);return}if(H)return;const o=e.body.scrollHeight,x=e.documentElement?.scrollHeight||0,$=F?.scrollHeight||0,we=Math.max(o,x,$);if(A){const h=Ne(),g=Math.max(200,h??Math.ceil(we));Me(w=>w===g?w:g)}},v=()=>{requestAnimationFrame(()=>{I||Q()})};T.current=v,Q(),v(),ke&&We().then(o=>{I||(o(e),H&&Be.injectScalingSystem(e),requestAnimationFrame(()=>{I||v()}))}).catch(()=>{I||v()});const ee=new ResizeObserver(()=>Q());ee.observe(e.body),F&&ee.observe(F);const xe=new MutationObserver(()=>{v()});return xe.observe(e.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["style","class"]}),()=>{I=!0,ee.disconnect(),xe.disconnect(),H&&n.contentWindow?.__mdf_cleanupScaling?.(),u&&e.removeEventListener("click",D,!0),setTimeout(()=>{be.unmount(),G.current=null,T.current=()=>{}},0)}},[]),t.useEffect(()=>{const n=()=>{_e(!!document.fullscreenElement)};return document.addEventListener("fullscreenchange",n),()=>document.removeEventListener("fullscreenchange",n)},[]),t.useEffect(()=>{const n=q.current;if(!n)return;const e=new ResizeObserver(u=>{ie(u[0]?.contentRect.width??n.clientWidth)});return e.observe(n),ie(n.clientWidth),()=>e.disconnect()},[]);const ge=t.useMemo(()=>{if(m||L===0||X)return;const n=Math.round(L*9/16);return{height:Math.max(n,oe)}},[m,L,oe,X]),Fe=()=>{const n=q.current||f.current;if(n){if(document.fullscreenElement){document.exitFullscreen().catch(()=>{});return}n.requestFullscreen&&n.requestFullscreen().catch(()=>{})}};t.useEffect(()=>{const n=G.current;if(!n)return;n.render(C.jsxRuntimeExports.jsx(Ve.default,{html:W,styleLoadingText:O,scriptLoadingText:M,disableLoadingOverlay:re,resetToken:ce,hasRootVhHeight:me,mode:l,stretchRootHeight:ue,enableScaling:H})),k.current=window.requestAnimationFrame(()=>{T.current?.(),H&&f.current?.contentWindow?.__mdf_triggerFitContent?.(),k.current=null});const e=setTimeout(()=>T.current?.(),100),u=setTimeout(()=>T.current?.(),500);return()=>{clearTimeout(e),clearTimeout(u)}},[W,O,M,ce,l]);const Ie=["w-full relative content-render-iframe-sandbox",m?"h-full overflow-auto flex flex-col":ge?"overflow-hidden flex items-center justify-center":"aspect-[16/9] overflow-hidden flex items-center justify-center"].filter(Boolean).join(" ");return C.jsxRuntimeExports.jsxs("div",{ref:q,"data-root-vh":me?"true":"false",className:Ie,style:j?{height:j,minHeight:j}:ge,children:[!V&&C.jsxRuntimeExports.jsx("button",{type:"button",onClick:Fe,className:"absolute top-2 right-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer",children:X?"退出全屏":d||"全屏浏览"}),l==="blackboard"&&i==="markdown"?C.jsxRuntimeExports.jsx("div",{onClick:()=>fe("click"),children:C.jsxRuntimeExports.jsx(qe.default,{content:c,disableSandboxLoadingOverlay:re})}):C.jsxRuntimeExports.jsx("iframe",{ref:f,sandbox:"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox",allow:"fullscreen",allowFullScreen:!0,className:[s,"w-full h-full mx-auto my-auto block"].filter(Boolean).join(" "),style:{height:j??"100%",minHeight:j,margin:"auto"}})]})};exports.default=Le;
|
|
24
24
|
//# sourceMappingURL=IframeSandbox.cjs.js.map
|