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,7 +1,7 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { useRef as i, useState as
|
|
3
|
-
import
|
|
4
|
-
const
|
|
1
|
+
import { j as R } from "../../_virtual/jsx-runtime.es.js";
|
|
2
|
+
import { useRef as i, useState as V, useEffect as I } from "react";
|
|
3
|
+
import Y from "../ui/loading-overlay-card.es.js";
|
|
4
|
+
const Z = [
|
|
5
5
|
"src",
|
|
6
6
|
"srcset",
|
|
7
7
|
"sizes",
|
|
@@ -15,48 +15,49 @@ const Y = [
|
|
|
15
15
|
"crossorigin",
|
|
16
16
|
"referrerpolicy",
|
|
17
17
|
"fetchpriority"
|
|
18
|
-
],
|
|
18
|
+
], W = (c) => Z.map(
|
|
19
19
|
(t) => `${t}:${c.getAttribute(t) || ""}`
|
|
20
|
-
).join("|"),
|
|
20
|
+
).join("|"), ee = (c) => {
|
|
21
21
|
const t = /* @__PURE__ */ new Map();
|
|
22
|
-
return c.querySelectorAll("img").forEach((
|
|
23
|
-
const o =
|
|
24
|
-
|
|
22
|
+
return c.querySelectorAll("img").forEach((f) => {
|
|
23
|
+
const o = f, n = W(o), m = t.get(n) || [];
|
|
24
|
+
m.push(o), t.set(n, m);
|
|
25
25
|
}), t;
|
|
26
|
-
},
|
|
27
|
-
const
|
|
28
|
-
|
|
26
|
+
}, te = (c, t) => {
|
|
27
|
+
const f = Array.from(c.attributes), o = new Set(
|
|
28
|
+
f.map((n) => n.name)
|
|
29
29
|
);
|
|
30
30
|
Array.from(t.attributes).forEach((n) => {
|
|
31
31
|
o.has(n.name) || t.removeAttribute(n.name);
|
|
32
|
-
}),
|
|
32
|
+
}), f.forEach((n) => {
|
|
33
33
|
t.setAttribute(n.name, n.value);
|
|
34
34
|
});
|
|
35
|
-
},
|
|
36
|
-
t.size && c.querySelectorAll("img").forEach((
|
|
37
|
-
const o =
|
|
38
|
-
h && (
|
|
35
|
+
}, re = (c, t) => {
|
|
36
|
+
t.size && c.querySelectorAll("img").forEach((f) => {
|
|
37
|
+
const o = f, n = W(o), m = t.get(n), h = m?.shift();
|
|
38
|
+
h && (te(o, h), o.replaceWith(h), m && m.length === 0 && t.delete(n));
|
|
39
39
|
});
|
|
40
|
-
},
|
|
40
|
+
}, ie = ({
|
|
41
41
|
html: c,
|
|
42
42
|
styleLoadingText: t,
|
|
43
|
-
scriptLoadingText:
|
|
43
|
+
scriptLoadingText: f,
|
|
44
44
|
resetToken: o = 0,
|
|
45
45
|
mode: n = "content",
|
|
46
|
-
hasRootVhHeight:
|
|
46
|
+
hasRootVhHeight: m = !1,
|
|
47
47
|
stretchRootHeight: h = !1,
|
|
48
|
-
enableScaling:
|
|
48
|
+
enableScaling: G = !1,
|
|
49
|
+
disableLoadingOverlay: N = !1
|
|
49
50
|
}) => {
|
|
50
|
-
const
|
|
51
|
+
const j = i(null), [U, E] = V(!1), [$, w] = V(!1), T = i([]), _ = i([]), k = i(0), B = i(0), y = i(null), g = i(null), x = i(!1), v = i(!1), F = i(!1), L = i(o), K = 200, u = (r) => {
|
|
51
52
|
r.current && (clearTimeout(r.current), r.current = null);
|
|
52
|
-
},
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
r(!1),
|
|
56
|
-
},
|
|
53
|
+
}, q = (r, a, l, D) => {
|
|
54
|
+
const p = performance.now() - l.current, A = Math.max(0, K - p);
|
|
55
|
+
u(a), a.current = window.setTimeout(() => {
|
|
56
|
+
r(!1), D?.(), a.current = null;
|
|
57
|
+
}, A);
|
|
57
58
|
};
|
|
58
|
-
|
|
59
|
-
const r =
|
|
59
|
+
I(() => {
|
|
60
|
+
const r = j.current?.ownerDocument;
|
|
60
61
|
if (!r) return;
|
|
61
62
|
const a = "sandbox-spinner-style";
|
|
62
63
|
let l = r.getElementById(a);
|
|
@@ -70,115 +71,117 @@ const Y = [
|
|
|
70
71
|
}
|
|
71
72
|
.overflow-y-auto { overflow-y: visible !important; }
|
|
72
73
|
`;
|
|
73
|
-
}, []),
|
|
74
|
-
o !==
|
|
75
|
-
const r =
|
|
74
|
+
}, []), I(() => {
|
|
75
|
+
o !== L.current && (F.current = !1, L.current = o), u(y), u(g), x.current = !1, v.current = !1;
|
|
76
|
+
const r = j.current;
|
|
76
77
|
if (!r) return;
|
|
77
78
|
const a = r.ownerDocument, l = a?.body;
|
|
78
79
|
if (!l) return;
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
Array.from(
|
|
80
|
+
const D = ee(r);
|
|
81
|
+
T.current.forEach((e) => e.remove()), T.current = [], _.current.forEach((e) => e.remove()), _.current = [], E(!1), w(!1);
|
|
82
|
+
const p = a.createElement("div");
|
|
83
|
+
p.innerHTML = c;
|
|
84
|
+
const A = (c.match(/<script[\s>]/gi) || []).length, O = (c.match(/<\/script>/gi) || []).length, P = A > 0 && A === O, b = [];
|
|
85
|
+
Array.from(p.querySelectorAll("style, script")).forEach((e) => {
|
|
85
86
|
if (e.tagName.toLowerCase() === "style") {
|
|
86
87
|
const s = a.createElement("style");
|
|
87
|
-
s.textContent = e.textContent || "", Array.from(e.attributes).forEach((
|
|
88
|
-
s.setAttribute(
|
|
89
|
-
}),
|
|
88
|
+
s.textContent = e.textContent || "", Array.from(e.attributes).forEach((d) => {
|
|
89
|
+
s.setAttribute(d.name, d.value);
|
|
90
|
+
}), b.push(s);
|
|
90
91
|
} else {
|
|
91
92
|
const s = a.createElement("script");
|
|
92
|
-
Array.from(e.attributes).forEach((
|
|
93
|
-
s.setAttribute(
|
|
94
|
-
}), s.textContent = e.textContent || "",
|
|
93
|
+
Array.from(e.attributes).forEach((d) => {
|
|
94
|
+
s.setAttribute(d.name, d.value);
|
|
95
|
+
}), s.textContent = e.textContent || "", b.push(s);
|
|
95
96
|
}
|
|
96
97
|
e.remove();
|
|
97
|
-
}),
|
|
98
|
-
const
|
|
98
|
+
}), re(p, D);
|
|
99
|
+
const z = b.some(
|
|
99
100
|
(e) => e.tagName.toLowerCase() === "style"
|
|
100
|
-
),
|
|
101
|
+
), H = b.some(
|
|
101
102
|
(e) => e.tagName.toLowerCase() === "script"
|
|
102
103
|
);
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
r.replaceChildren(...
|
|
104
|
+
z && (x.current = !0, k.current = performance.now(), u(y), E(!0)), H && (v.current = !0, B.current = performance.now(), u(g), w(!0)), !!p.firstElementChild && (F.current = !0);
|
|
105
|
+
const X = Array.from(p.childNodes);
|
|
106
|
+
r.replaceChildren(...X), b.forEach((e) => {
|
|
106
107
|
if (e.tagName.toLowerCase() === "style") {
|
|
107
|
-
a.head?.appendChild(e),
|
|
108
|
+
a.head?.appendChild(e), T.current.push(e);
|
|
108
109
|
return;
|
|
109
110
|
}
|
|
110
|
-
if (
|
|
111
|
-
const s = e,
|
|
111
|
+
if (P) {
|
|
112
|
+
const s = e, d = s.textContent || "";
|
|
112
113
|
if (!s.src)
|
|
113
114
|
try {
|
|
114
|
-
new Function(
|
|
115
|
+
new Function(d);
|
|
115
116
|
} catch {
|
|
116
117
|
s.remove();
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
120
|
try {
|
|
120
|
-
l.appendChild(s),
|
|
121
|
+
l.appendChild(s), _.current.push(s);
|
|
121
122
|
} catch {
|
|
122
123
|
s.remove();
|
|
123
124
|
}
|
|
124
125
|
} else
|
|
125
126
|
e.remove();
|
|
126
|
-
}),
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
}), G && r.ownerDocument?.defaultView?.__mdf_triggerFitContent?.(), requestAnimationFrame(() => {
|
|
128
|
+
z && q(
|
|
129
|
+
E,
|
|
130
|
+
y,
|
|
131
|
+
k,
|
|
131
132
|
() => {
|
|
132
|
-
|
|
133
|
+
x.current = !1;
|
|
133
134
|
}
|
|
134
|
-
),
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
), H && q(
|
|
136
|
+
w,
|
|
137
|
+
g,
|
|
138
|
+
B,
|
|
138
139
|
() => {
|
|
139
|
-
|
|
140
|
+
v.current = !1;
|
|
140
141
|
}
|
|
141
142
|
);
|
|
142
143
|
});
|
|
143
|
-
}, [c, o,
|
|
144
|
+
}, [c, o, G]), I(
|
|
144
145
|
() => () => {
|
|
145
|
-
|
|
146
|
+
u(y), u(g);
|
|
146
147
|
},
|
|
147
148
|
[]
|
|
148
|
-
)
|
|
149
|
-
|
|
149
|
+
), I(() => {
|
|
150
|
+
N && (u(y), u(g), x.current = !1, v.current = !1, E(!1), w(!1));
|
|
151
|
+
}, [N]);
|
|
152
|
+
const S = N ? null : $ || v.current ? f || "Building scripts cache..." : U || x.current ? t || "Building styles..." : null, M = n === "blackboard", C = M && h, Q = {
|
|
150
153
|
position: "relative",
|
|
151
154
|
width: "100%",
|
|
152
155
|
height: "100%",
|
|
153
156
|
display: "flex",
|
|
154
157
|
flexDirection: "column",
|
|
155
158
|
// Keep blackboard scroll behavior while centering content in non-blackboard mode
|
|
156
|
-
justifyContent:
|
|
157
|
-
},
|
|
158
|
-
pointerEvents:
|
|
159
|
-
margin:
|
|
159
|
+
justifyContent: C ? "flex-start" : M ? "space-around" : "flex-start"
|
|
160
|
+
}, J = {
|
|
161
|
+
pointerEvents: S ? "none" : void 0,
|
|
162
|
+
margin: M ? void 0 : "auto 0",
|
|
160
163
|
width: "100%",
|
|
161
|
-
height:
|
|
162
|
-
minHeight:
|
|
163
|
-
flex:
|
|
164
|
+
height: C ? "100%" : void 0,
|
|
165
|
+
minHeight: C ? 0 : void 0,
|
|
166
|
+
flex: C ? "1 1 auto" : void 0
|
|
164
167
|
};
|
|
165
|
-
return /* @__PURE__ */
|
|
168
|
+
return /* @__PURE__ */ R.jsxs(
|
|
166
169
|
"div",
|
|
167
170
|
{
|
|
168
|
-
"data-root-vh":
|
|
171
|
+
"data-root-vh": m ? "true" : "false",
|
|
169
172
|
className: "sandbox-wrapper",
|
|
170
|
-
style:
|
|
171
|
-
"aria-busy": !!
|
|
173
|
+
style: Q,
|
|
174
|
+
"aria-busy": !!S,
|
|
172
175
|
children: [
|
|
173
|
-
/* @__PURE__ */
|
|
176
|
+
/* @__PURE__ */ R.jsx(
|
|
174
177
|
"div",
|
|
175
178
|
{
|
|
176
|
-
ref:
|
|
179
|
+
ref: j,
|
|
177
180
|
className: "sandbox-container",
|
|
178
|
-
style:
|
|
181
|
+
style: J
|
|
179
182
|
}
|
|
180
183
|
),
|
|
181
|
-
|
|
184
|
+
S && /* @__PURE__ */ R.jsx(
|
|
182
185
|
"div",
|
|
183
186
|
{
|
|
184
187
|
style: {
|
|
@@ -190,7 +193,7 @@ const Y = [
|
|
|
190
193
|
justifyContent: "center",
|
|
191
194
|
pointerEvents: "none"
|
|
192
195
|
},
|
|
193
|
-
children: /* @__PURE__ */
|
|
196
|
+
children: /* @__PURE__ */ R.jsx(Y, { message: S })
|
|
194
197
|
}
|
|
195
198
|
)
|
|
196
199
|
]
|
|
@@ -198,6 +201,6 @@ const Y = [
|
|
|
198
201
|
);
|
|
199
202
|
};
|
|
200
203
|
export {
|
|
201
|
-
|
|
204
|
+
ie as default
|
|
202
205
|
};
|
|
203
206
|
//# sourceMappingURL=SandboxApp.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxApp.es.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport LoadingOverlayCard from \"../ui/loading-overlay-card\";\nimport type { ScalingWindow } from \"./utils/iframe-scaling\";\n\nexport interface SandboxAppProps {\n html: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n stretchRootHeight?: boolean;\n enableScaling?: boolean;\n}\n\nconst IMAGE_REUSE_ATTRIBUTES = [\n \"src\",\n \"srcset\",\n \"sizes\",\n \"alt\",\n \"class\",\n \"width\",\n \"height\",\n \"style\",\n \"loading\",\n \"decoding\",\n \"crossorigin\",\n \"referrerpolicy\",\n \"fetchpriority\",\n];\n\nconst getImageReuseKey = (image: HTMLImageElement) =>\n IMAGE_REUSE_ATTRIBUTES.map(\n (attribute) => `${attribute}:${image.getAttribute(attribute) || \"\"}`\n ).join(\"|\");\n\nconst collectReusableImages = (root: ParentNode) => {\n const imageMap = new Map<string, HTMLImageElement[]>();\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n const key = getImageReuseKey(image);\n const bucket = imageMap.get(key) || [];\n bucket.push(image);\n imageMap.set(key, bucket);\n });\n return imageMap;\n};\n\nconst syncImageAttributes = (\n sourceImage: HTMLImageElement,\n targetImage: HTMLImageElement\n) => {\n const sourceAttributes = Array.from(sourceImage.attributes);\n const sourceAttributeNames = new Set(\n sourceAttributes.map((attribute) => attribute.name)\n );\n\n Array.from(targetImage.attributes).forEach((attribute) => {\n if (!sourceAttributeNames.has(attribute.name)) {\n targetImage.removeAttribute(attribute.name);\n }\n });\n\n sourceAttributes.forEach((attribute) => {\n targetImage.setAttribute(attribute.name, attribute.value);\n });\n};\n\nconst reuseRenderedImages = (\n root: ParentNode,\n imageMap: Map<string, HTMLImageElement[]>\n) => {\n if (!imageMap.size) return;\n\n root.querySelectorAll(\"img\").forEach((node) => {\n const nextImage = node as HTMLImageElement;\n const key = getImageReuseKey(nextImage);\n const bucket = imageMap.get(key);\n const preservedImage = bucket?.shift();\n if (!preservedImage) return;\n\n syncImageAttributes(nextImage, preservedImage);\n nextImage.replaceWith(preservedImage);\n\n if (bucket && bucket.length === 0) {\n imageMap.delete(key);\n }\n });\n};\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n stretchRootHeight = false,\n enableScaling = false,\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\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 doc.head?.appendChild(styleEl);\n }\n styleEl.textContent = `\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { position: relative; width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n .justify-\\\\[safe_center\\\\]{\n justify-content: safe center;\n }\n .overflow-y-auto { overflow-y: visible !important; }\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 const reusableImages = collectReusableImages(container);\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 setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n const wrapper = doc.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 reuseRenderedImages(wrapper, reusableImages);\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 if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.replaceChildren(...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 if (enableScaling) {\n const win = container.ownerDocument?.defaultView as ScalingWindow | null;\n win?.__mdf_triggerFitContent?.();\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, enableScaling]);\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 return null;\n })();\n\n const isBlackboard = mode === \"blackboard\";\n const shouldStretchRootHeight = isBlackboard && stretchRootHeight;\n const sandboxWrapperStyle: React.CSSProperties = {\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n flexDirection: \"column\",\n // Keep blackboard scroll behavior while centering content in non-blackboard mode\n justifyContent: shouldStretchRootHeight\n ? \"flex-start\"\n : isBlackboard\n ? \"space-around\"\n : \"flex-start\",\n };\n const sandboxContainerStyle: React.CSSProperties = {\n pointerEvents: overlayMessage ? \"none\" : undefined,\n margin: isBlackboard ? undefined : \"auto 0\",\n width: \"100%\",\n height: shouldStretchRootHeight ? \"100%\" : undefined,\n minHeight: shouldStretchRootHeight ? 0 : undefined,\n flex: shouldStretchRootHeight ? \"1 1 auto\" : undefined,\n };\n\n return (\n <div\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={sandboxWrapperStyle}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={sandboxContainerStyle}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n zIndex: 20,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n pointerEvents: \"none\",\n }}\n >\n <LoadingOverlayCard message={overlayMessage} />\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["IMAGE_REUSE_ATTRIBUTES","getImageReuseKey","image","attribute","collectReusableImages","root","imageMap","node","key","bucket","syncImageAttributes","sourceImage","targetImage","sourceAttributes","sourceAttributeNames","reuseRenderedImages","nextImage","preservedImage","SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","stretchRootHeight","enableScaling","containerRef","useRef","isGeneratingStyles","setIsGeneratingStyles","useState","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","reusableImages","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","shouldStretchRootHeight","sandboxWrapperStyle","sandboxContainerStyle","jsxs","jsx","LoadingOverlayCard"],"mappings":";;;AAeA,MAAMA,IAAyB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAC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IAC3C,WAAWA,IAA0B,IAAI;AAAA,IACzC,MAAMA,IAA0B,aAAa;AAAA,EAAA;AAG/C,SACEG,gBAAAA,EAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,gBAActD,IAAkB,SAAS;AAAA,MACzC,WAAU;AAAA,MACV,OAAOoD;AAAA,MACP,aAAW,CAAC,CAACH;AAAA,MAEb,UAAA;AAAA,QAAAM,gBAAAA,EAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,KAAKpD;AAAA,YACL,WAAU;AAAA,YACV,OAAOkD;AAAA,UAAA;AAAA,QAAA;AAAA,QAERJ,KACCM,gBAAAA,EAAAA;AAAAA,UAAC;AAAA,UAAA;AAAA,YACC,OAAO;AAAA,cACL,UAAU;AAAA,cACV,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,eAAe;AAAA,YAAA;AAAA,YAGjB,UAAAA,gBAAAA,EAAAA,IAACC,GAAA,EAAmB,SAASP,EAAA,CAAgB;AAAA,UAAA;AAAA,QAAA;AAAA,MAC/C;AAAA,IAAA;AAAA,EAAA;AAIR;"}
|
|
1
|
+
{"version":3,"file":"SandboxApp.es.js","sources":["../../../src/components/ContentRender/SandboxApp.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport LoadingOverlayCard from \"../ui/loading-overlay-card\";\nimport type { ScalingWindow } from \"./utils/iframe-scaling\";\n\nexport interface SandboxAppProps {\n html: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n stretchRootHeight?: boolean;\n enableScaling?: boolean;\n disableLoadingOverlay?: boolean;\n}\n\nconst IMAGE_REUSE_ATTRIBUTES = [\n \"src\",\n \"srcset\",\n \"sizes\",\n \"alt\",\n \"class\",\n \"width\",\n \"height\",\n \"style\",\n \"loading\",\n \"decoding\",\n \"crossorigin\",\n \"referrerpolicy\",\n \"fetchpriority\",\n];\n\nconst getImageReuseKey = (image: HTMLImageElement) =>\n IMAGE_REUSE_ATTRIBUTES.map(\n (attribute) => `${attribute}:${image.getAttribute(attribute) || \"\"}`\n ).join(\"|\");\n\nconst collectReusableImages = (root: ParentNode) => {\n const imageMap = new Map<string, HTMLImageElement[]>();\n root.querySelectorAll(\"img\").forEach((node) => {\n const image = node as HTMLImageElement;\n const key = getImageReuseKey(image);\n const bucket = imageMap.get(key) || [];\n bucket.push(image);\n imageMap.set(key, bucket);\n });\n return imageMap;\n};\n\nconst syncImageAttributes = (\n sourceImage: HTMLImageElement,\n targetImage: HTMLImageElement\n) => {\n const sourceAttributes = Array.from(sourceImage.attributes);\n const sourceAttributeNames = new Set(\n sourceAttributes.map((attribute) => attribute.name)\n );\n\n Array.from(targetImage.attributes).forEach((attribute) => {\n if (!sourceAttributeNames.has(attribute.name)) {\n targetImage.removeAttribute(attribute.name);\n }\n });\n\n sourceAttributes.forEach((attribute) => {\n targetImage.setAttribute(attribute.name, attribute.value);\n });\n};\n\nconst reuseRenderedImages = (\n root: ParentNode,\n imageMap: Map<string, HTMLImageElement[]>\n) => {\n if (!imageMap.size) return;\n\n root.querySelectorAll(\"img\").forEach((node) => {\n const nextImage = node as HTMLImageElement;\n const key = getImageReuseKey(nextImage);\n const bucket = imageMap.get(key);\n const preservedImage = bucket?.shift();\n if (!preservedImage) return;\n\n syncImageAttributes(nextImage, preservedImage);\n nextImage.replaceWith(preservedImage);\n\n if (bucket && bucket.length === 0) {\n imageMap.delete(key);\n }\n });\n};\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n stretchRootHeight = false,\n enableScaling = false,\n disableLoadingOverlay = false,\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\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 doc.head?.appendChild(styleEl);\n }\n styleEl.textContent = `\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { position: relative; width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n .justify-\\\\[safe_center\\\\]{\n justify-content: safe center;\n }\n .overflow-y-auto { overflow-y: visible !important; }\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 const reusableImages = collectReusableImages(container);\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 setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n const wrapper = doc.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 reuseRenderedImages(wrapper, reusableImages);\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 if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.replaceChildren(...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 if (enableScaling) {\n const win = container.ownerDocument?.defaultView as ScalingWindow | null;\n win?.__mdf_triggerFitContent?.();\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, enableScaling]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n },\n []\n );\n\n useEffect(() => {\n if (!disableLoadingOverlay) {\n return;\n }\n\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n }, [disableLoadingOverlay]);\n\n const overlayMessage = (() => {\n if (disableLoadingOverlay) {\n return null;\n }\n\n if (isGeneratingScripts || hasScriptsRef.current)\n return scriptLoadingText || \"Building scripts cache...\";\n if (isGeneratingStyles || hasStylesRef.current)\n return styleLoadingText || \"Building styles...\";\n return null;\n })();\n\n const isBlackboard = mode === \"blackboard\";\n const shouldStretchRootHeight = isBlackboard && stretchRootHeight;\n const sandboxWrapperStyle: React.CSSProperties = {\n position: \"relative\",\n width: \"100%\",\n height: \"100%\",\n display: \"flex\",\n flexDirection: \"column\",\n // Keep blackboard scroll behavior while centering content in non-blackboard mode\n justifyContent: shouldStretchRootHeight\n ? \"flex-start\"\n : isBlackboard\n ? \"space-around\"\n : \"flex-start\",\n };\n const sandboxContainerStyle: React.CSSProperties = {\n pointerEvents: overlayMessage ? \"none\" : undefined,\n margin: isBlackboard ? undefined : \"auto 0\",\n width: \"100%\",\n height: shouldStretchRootHeight ? \"100%\" : undefined,\n minHeight: shouldStretchRootHeight ? 0 : undefined,\n flex: shouldStretchRootHeight ? \"1 1 auto\" : undefined,\n };\n\n return (\n <div\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={sandboxWrapperStyle}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={sandboxContainerStyle}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n zIndex: 20,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n pointerEvents: \"none\",\n }}\n >\n <LoadingOverlayCard message={overlayMessage} />\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["IMAGE_REUSE_ATTRIBUTES","getImageReuseKey","image","attribute","collectReusableImages","root","imageMap","node","key","bucket","syncImageAttributes","sourceImage","targetImage","sourceAttributes","sourceAttributeNames","reuseRenderedImages","nextImage","preservedImage","SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","stretchRootHeight","enableScaling","disableLoadingOverlay","containerRef","useRef","isGeneratingStyles","setIsGeneratingStyles","useState","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","reusableImages","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","shouldStretchRootHeight","sandboxWrapperStyle","sandboxContainerStyle","jsxs","jsx","LoadingOverlayCard"],"mappings":";;;AAgBA,MAAMA,IAAyB;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAEMC,IAAmB,CAACC,MACxBF,EAAuB;AAAA,EACrB,CAACG,MAAc,GAAGA,CAAS,IAAID,EAAM,aAAaC,CAAS,KAAK,EAAE;AACpE,EAAE,KAAK,GAAG,GAENC,KAAwB,CAACC,MAAqB;AAClD,QAAMC,wBAAe,IAAA;AACrB,SAAAD,EAAK,iBAAiB,KAAK,EAAE,QAAQ,CAACE,MAAS;AAC7C,UAAML,IAAQK,GACRC,IAAMP,EAAiBC,CAAK,GAC5BO,IAASH,EAAS,IAAIE,CAAG,KAAK,CAAA;AACpC,IAAAC,EAAO,KAAKP,CAAK,GACjBI,EAAS,IAAIE,GAAKC,CAAM;AAAA,EAC1B,CAAC,GACMH;AACT,GAEMI,KAAsB,CAC1BC,GACAC,MACG;AACH,QAAMC,IAAmB,MAAM,KAAKF,EAAY,UAAU,GACpDG,IAAuB,IAAI;AAAA,IAC/BD,EAAiB,IAAI,CAACV,MAAcA,EAAU,IAAI;AAAA,EAAA;AAGpD,QAAM,KAAKS,EAAY,UAAU,EAAE,QAAQ,CAACT,MAAc;AACxD,IAAKW,EAAqB,IAAIX,EAAU,IAAI,KAC1CS,EAAY,gBAAgBT,EAAU,IAAI;AAAA,EAE9C,CAAC,GAEDU,EAAiB,QAAQ,CAACV,MAAc;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,gBAAgB;AAAA,cAChB,eAAe;AAAA,YAAA;AAAA,YAGjB,UAAAA,gBAAAA,EAAAA,IAACC,GAAA,EAAmB,SAASP,EAAA,CAAgB;AAAA,UAAA;AAAA,QAAA;AAAA,MAC/C;AAAA,IAAA;AAAA,EAAA;AAIR;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("../../_virtual/jsx-runtime.cjs.js"),t=require("react"),an=require("../../lib/sandboxInteraction.cjs.js"),z=require("../../lib/utils.cjs.js"),dn=require("../ui/loading-overlay-card.cjs.js"),fn=require("../ContentRender/ContentRender.cjs.js"),St=require("../ContentRender/IframeSandbox.cjs.js");require("../ui/inputGroup/input-group.cjs.js");const Et=require("../../lib/interaction-defaults.cjs.js"),Ee=require("../../lib/mobileDevice.cjs.js"),mn=require("./Player.cjs.js"),pn=require("./SubtitleOverlay.cjs.js"),hn=require("./constants.cjs.js"),xn=require("./SlideFullscreenHint.cjs.js"),bn=require("./useSlide.cjs.js"),vn=require("./useWakePlayerFromIframe.cjs.js"),le=require("./utils/mobileScreenMode.cjs.js"),Sn=require("./utils/interactionPlayback.cjs.js"),En=require("./utils/appendedMarkerAdvance.cjs.js"),yn=require("./utils/playbackSequence.cjs.js"),yt=require("./utils/playerCustomActions.cjs.js"),gn=require("./utils/playbackTimeStore.cjs.js"),Rn=require("./utils/playerToggleMode.cjs.js");;/* empty css */const In=require("../../markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/chevron-left.cjs.js"),An=2e3,wn=300,Cn=160,Mn=16,gt=t.memo(({content:F,title:O,defaultButtonText:b,defaultInputText:G,defaultSelectedValues:v,confirmButtonText:q,copyButtonText:$,copiedButtonText:ye,onSend:ge,readonly:B=!1})=>r.jsxRuntimeExports.jsxs("div",{className:"slide-player__interaction-card",children:[r.jsxRuntimeExports.jsx("div",{className:"slide-player__interaction-header",children:r.jsxRuntimeExports.jsx("p",{className:"slide-player__interaction-title",children:O})}),r.jsxRuntimeExports.jsx("div",{className:"slide-player__interaction-body",children:r.jsxRuntimeExports.jsx(fn.default,{content:F,defaultButtonText:b,defaultInputText:G,defaultSelectedValues:v,confirmButtonText:q,copyButtonText:$,copiedButtonText:ye,onSend:ge,readonly:B,enableTypewriter:!1,sandboxMode:"content"})})]}));gt.displayName="InteractionOverlayCard";const _n=(F,O)=>F.length===O.length&&F.every((b,G)=>{const v=O[G];return b.sequence_number===v?.sequence_number&&b.type===v?.type&&b.content===v?.content}),kn=({elementList:F=[],showPlayer:O=!0,playerAlwaysVisible:b=!1,playerClassName:G,fullscreenHeader:v,playerCustomActions:q,playerCustomActionPauseOnActive:$=!0,bufferingText:ye="Buffering...",interactionTitle:ge,interactionTexts:B,playerTexts:Be,playerAutoHideDelay:Re=3e3,markerAutoAdvanceDelay:Le=An,interactionDefaultValueOptions:ue,onSend:Ne,onPlayerVisibilityChange:Ie,onMobileViewModeChange:Ve,onStepChange:Ke,enableIframeScaling:Rt=!0,className:It,onPointerDown:De,...At})=>{const ie=t.useRef(null),He=t.useRef(null),Ae=t.useRef(null),Ue=t.useRef(null),Y=t.useRef(null),X=t.useRef(null),J=t.useRef(null),Q=t.useRef(null),We=t.useRef(null),ze=t.useRef([]),ce=t.useRef(!1),L=t.useRef(null),Ge=t.useRef(null),$e=t.useRef({markerCount:0,currentIndex:-1,canGoNext:!1}),{currentElementList:M,stepElementLists:Ye,slideElementList:_,currentIndex:c,audioList:d,currentAudioSequenceIndexes:ae,currentStepHasSpeakableElement:p,currentInteractionElement:i,canGoPrev:wt,canGoNext:x,handlePrev:Xe,handleNext:g}=bn.default(F),Z=t.useMemo(()=>{if(!(c<0))return _[c]},[c,_]),Ct=_.filter(e=>e.is_renderable!==!1).length===1,S=O&&(_.length>0||d.length>0||!!i),R=t.useMemo(()=>ae.map(e=>d[e]?.audioKey).filter(e=>!!e),[d,ae]),[Je,de]=t.useState(!0),[fe,ee]=t.useState(!1),[te,Qe]=t.useState(!0),[f,N]=t.useState(null),[Mt,E]=t.useState(!1),[I,Ze]=t.useState(!1),[_t,we]=t.useState(!1),[et,kt]=t.useState(!0),[Ce,Me]=t.useState(!1),[s,_e]=t.useState(),[me,pe]=t.useState(!1),[Tt,ne]=t.useState(0),[jt,Pt]=t.useState(!1),A=t.useMemo(()=>Ee.isMobileDevice(),[]),[he,ke]=t.useState(le.DEFAULT_MOBILE_VIEW_MODE),[tt,Te]=t.useState(!1),[je,nt]=t.useState(()=>A?Ee.isLandscapeViewport():!1),[Ft,xe]=t.useState(!1),V=t.useMemo(()=>gn.createPlaybackTimeStore(),[]),{effectiveMobileViewMode:T,isImmersiveMobileFullscreen:K,isNativeMobileFullscreen:rt,shouldRotateFullscreenViewport:Ot}=t.useMemo(()=>le.resolveMobileViewModeState({hasManualMobileViewMode:tt,isMobileDevice:A,mobileViewMode:he}),[tt,A,je,he]),st=t.useRef(T),w=S&&(b||Je),qt=K&&w,Bt=K&&w,Lt=K||rt,Nt=Be?.fullscreenHintText??hn.DEFAULT_SLIDE_PLAYER_TEXTS.fullscreenHintText,Vt=t.useCallback(e=>{Te(!0),ke(e)},[]),ot=t.useCallback(()=>{Te(!1),ke(le.DEFAULT_MOBILE_VIEW_MODE)},[]),Kt=t.useCallback(()=>{ot(),v?.onBack?.()},[v,ot]),Dt=t.useCallback(()=>{xe(!1)},[]),lt=t.useCallback(e=>{Me(e)},[]),ut=t.useCallback(()=>{Me(e=>!e)},[]),{mountedStepStates:Ht,currentMountedStateIndex:Ut}=t.useMemo(()=>{const e=[],n=new Map;return Ye.forEach((o,a)=>{const l=e.findIndex(u=>_n(u.elementList,o));if(l>=0){e[l]?.sourceStepIndexes.push(a),n.set(a,l);return}e.push({elementList:o,sourceStepIndexes:[a]}),n.set(a,e.length-1)}),{mountedStepStates:e,currentMountedStateIndex:c>=0?n.get(c)??-1:-1}},[c,Ye]),it=t.useMemo(()=>String(c),[c]),m=t.useMemo(()=>f?d.findIndex(e=>(e.audioKey??"")===f):-1,[d,f]),Pe=t.useMemo(()=>m>=0?d[m]:void 0,[d,m]),Wt=Pe?.element?.subtitle_cues??[],be=t.useMemo(()=>R[0]??"none",[R]),Fe=t.useMemo(()=>({currentElement:yt.resolvePlayerCustomActionElement({currentAudioIndex:m,currentAudioSequenceIndexes:ae,audioList:d,currentInteractionElement:s,currentStepElement:Z}),currentIndex:c,currentStepElement:Z,isActive:Ce,setActive:lt,toggleActive:ut}),[s,d,m,ae,c,Z,Ce,lt,ut]),Oe=t.useMemo(()=>yt.getPlayerCustomActionCount(q,Fe),[Fe,q]),zt=t.useMemo(()=>({"--slide-player-custom-action-count":String(Oe),"--slide-player-mobile-control-count":String(Oe+4)}),[Oe]),ct=R.length>0,at=t.useMemo(()=>i?`${i.sequence_number??"none"}:${String(i.content??"")}`:"none",[i]),re=t.useMemo(()=>[it,at].join("|"),[at,it]),Gt=t.useMemo(()=>[re,Pe?.audioKey??"none",String(m)].join("|"),[m,Pe?.audioKey,re]),dt=!!t.useMemo(()=>!be||be==="none"?"":d.find(n=>n.audioKey===be)?.audioUrl?.trim()??"",[d,be]),j=$&&!!q&&Ce,se=t.useMemo(()=>Rn.shouldUseAutoAdvanceToggle({canGoNext:x,currentAudioIndex:m,currentStepHasSpeakableElement:p,hasInteraction:!!i}),[x,m,i,p]),P=t.useCallback(()=>{Y.current!==null&&(window.clearTimeout(Y.current),Y.current=null)},[]),k=t.useCallback(()=>{J.current!==null&&(window.clearTimeout(J.current),J.current=null)},[]),C=t.useCallback(()=>{Q.current!==null&&(window.clearTimeout(Q.current),Q.current=null)},[]),D=t.useCallback(()=>{X.current!==null&&(window.clearTimeout(X.current),X.current=null)},[]),H=t.useCallback(()=>{D(),k(),C(),N(null),V.reset(),E(!1),Ze(!1),we(!1),_e(void 0),pe(!1),ne(0)},[D,k,C,V]),U=t.useCallback(()=>{const e=R[0];return e?(N(e),!0):!1},[R]),ve=t.useCallback(()=>{k(),C(),pe(!1),ne(0),!U()&&x&&g()},[x,k,C,g,U]),ft=t.useCallback(e=>{if(C(),!e)return;const n=()=>{Q.current=null,ne(Cn),pe(!0),L.current=null};Q.current=window.setTimeout(n,wn)},[C]),h=t.useCallback((e=fe)=>{S&&(de(!0),P(),!(b||!e||Re<=0)&&(Y.current=window.setTimeout(()=>{de(!1),Y.current=null},Re)))},[P,fe,b,Re,S]),oe=!!(i?.readonly||i?.user_input?.trim()),W=!!i&&!oe;t.useEffect(()=>{Qe(!0),$&&Me(!1)},[c,$]),t.useEffect(()=>()=>{D(),P(),k(),C()},[D,k,C,P]),t.useEffect(()=>(Ie?.(w),()=>{Ie?.(!1)}),[Ie,w]),t.useEffect(()=>{A||he===le.DEFAULT_MOBILE_VIEW_MODE||(Te(!1),ke(le.DEFAULT_MOBILE_VIEW_MODE))},[A,he]),t.useEffect(()=>{if(!A){nt(!1);return}const e=()=>{nt(Ee.isLandscapeViewport())};return e(),Ee.subscribeMobileDeviceChange(e)},[A]),t.useEffect(()=>{Ve?.(T)},[T,Ve]),t.useEffect(()=>{const o=st.current!=="fullscreen"&&T==="fullscreen"&&!je;if(st.current=T,!A){xe(!1);return}if(o){xe(!0);return}T!=="fullscreen"&&xe(!1)},[T,A,je]),t.useEffect(()=>{Ke?.(Z,c)},[c,Z,Ke]),t.useEffect(()=>{const e=$e.current,n=En.shouldAutoAdvanceIntoAppendedMarker({previousMarkerCount:e.markerCount,nextMarkerCount:_.length,previousIndex:e.currentIndex,previousCanGoNext:e.canGoNext,nextCanGoNext:x,currentAudioKey:f,hasCompletedCurrentStepAudio:I,hasResolvedCurrentInteraction:oe,currentStepHasSpeakableElement:p,currentInteractionElement:i,isAutoAdvanceEnabled:te,shouldUseSilentStepAutoAdvanceToggle:se});$e.current={markerCount:_.length,currentIndex:c,canGoNext:x},n&&g()},[x,f,c,i,p,g,I,oe,te,se,_.length]),t.useEffect(()=>{if(!S){P(),de(!1);return}if(b){P(),de(!0);return}fe||h(!0)},[P,fe,b,S,h]),t.useEffect(()=>{if(typeof window>"u")return;const e=n=>{n.origin===window.location.origin&&an.isSandboxInteractionMessage(n.data)&&n.data.eventType==="click"&&S&&(ee(!0),h(!0))};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[S,h]),vn.default({sectionRef:ie,enabled:S,onWake:()=>{ee(!0),h(!0)}}),t.useEffect(()=>{const{hasPlaybackContextChanged:e,shouldInitializeAudioSequence:n}=yn.getPlaybackSequenceTransition({previousResetKey:Ge.current,nextResetKey:re,currentAudioKey:f,hasCompletedCurrentStepAudio:I});Ge.current=re;const o=L.current===c&&!!i,a=Sn.shouldPresentInteractionOverlay({hasInteraction:!!i,shouldBlockPlaybackForInteraction:W,shouldOpenInteractionOverlayAfterAudio:o,hasPlaybackContextChanged:e,hasResolvedCurrentInteraction:oe,currentStepHasSpeakableElement:p});if(e&&H(),!(M.length===0&&!i)&&!j){if(i&&_e(i),a){ft(i);return}if(C(),L.current=null,!!n&&!U()){if(p){E(!0);return}if(x&&!(se&&!te))return X.current=window.setTimeout(()=>{X.current=null,g()},Le),()=>{D()}}}},[x,D,M.length,i,f,re,p,Le,g,I,te,oe,W,C,H,ft,U,j,se]),t.useEffect(()=>{if(j||!p||W){E(!1);return}if(I){E(!1);return}if(ct){E(!1);return}E(!0)},[ct,p,I,j,W]),t.useEffect(()=>{f||R.length===0||j||!p||W||I||U()},[f,R,p,I,j,W,U]),t.useEffect(()=>{!f||m>=0||N(null)},[m,f]),t.useEffect(()=>{m>=0||V.reset()},[m,V]),t.useEffect(()=>{we(!1)},[Gt]);const mt=t.useMemo(()=>{if(!s)return{};const e=!!s.user_input?.trim();return Et.getInteractionDefaultValues(typeof s.content=="string"?s.content:void 0,s.user_input,e?void 0:ue)},[s,ue]),$t=t.useMemo(()=>{if(!s)return;const e=!!s.user_input?.trim();return Et.getInteractionDefaultSelectedValues(typeof s.content=="string"?s.content:void 0,s.user_input,e?void 0:ue)},[s,ue]),pt=!!s?.user_input?.trim(),ht=!!s?.readonly||pt,xt=ht||pt,qe=!!s&&me,Yt=t.useCallback(e=>{const o=[...e.selectedValues??[],e.inputText?.trim()??"",e.buttonText?.trim()??""].filter(Boolean).join(", ");_e(a=>!a||!o?a:{...a,user_input:o}),Ne?.(e,s),ve()},[s,ve,Ne]);t.useEffect(()=>{const e=()=>{Pt(document.fullscreenElement===ie.current)};return e(),document.addEventListener("fullscreenchange",e),()=>{document.removeEventListener("fullscreenchange",e)}},[]),t.useEffect(()=>{if(!qe){ne(0);return}const e=We.current;if(!e)return;const n=()=>{const a=Math.ceil(e.getBoundingClientRect().height);ne(a+Mn)};if(n(),typeof ResizeObserver>"u")return;const o=new ResizeObserver(()=>{n()});return o.observe(e),()=>{o.disconnect()}},[qe]),t.useEffect(()=>{if(k(),!(!me||!xt))return J.current=window.setTimeout(()=>{J.current=null,ve()},2e3),()=>{k()}},[k,ve,me,xt]);const Xt=(e,n={})=>e?e.type==="slot"?r.jsxRuntimeExports.jsx(r.jsxRuntimeExports.Fragment,{children:e.content}):e.type==="html"?r.jsxRuntimeExports.jsx(St.default,{className:"content-render-iframe",hideFullScreen:!0,mode:"blackboard",replaceRootScreenHeightWithFull:n.replaceRootScreenHeightWithFull,type:"sandbox",content:e.content,enableScaling:Rt}):r.jsxRuntimeExports.jsx(St.default,{className:"content-render-iframe",hideFullScreen:!0,mode:"blackboard",type:"markdown",content:e.content}):null,Jt=(e=[],n=!1)=>{if(e.length===0)return null;const o=e.filter(l=>l.is_renderable!==!1).length,a=e.reduce((l,u,y)=>u.is_renderable!==!1?y:l,-1);return r.jsxRuntimeExports.jsx("div",{className:"slide-stage__content flex w-full flex-col gap-4",children:e.map((l,u)=>{const y=l.type==="html"&&l.is_renderable===!1;return r.jsxRuntimeExports.jsx("div",{ref:n&&u===a?Ue:null,"aria-hidden":y||void 0,className:z.cn("w-full shrink-0",o===1&&l.is_renderable!==!1&&"slide-element--single",y?"pointer-events-none fixed left-[-200vw] top-0 -z-10 h-[100dvh] w-[100vw] overflow-hidden opacity-0":l.is_renderable===!1&&"hidden"),children:Xt(l,{replaceRootScreenHeightWithFull:o===1&&l.type==="html"&&l.is_renderable!==!1})},l.sequence_number??`${l.type}-${u}`)})})},Qt=t.useCallback(()=>{const e=ie.current;if(e){if(document.fullscreenElement===e){document.exitFullscreen().catch(()=>{});return}e.requestFullscreen?.().catch(()=>{})}},[]),bt=t.useCallback(()=>{const e=Ae.current;e&&e.scrollTo({top:e.scrollHeight,behavior:"smooth"})},[]),Zt=t.useCallback(()=>{ce.current=!0,L.current=null,ee(!0),E(!1),h(!0),H(),Xe()},[Xe,H,h]),en=t.useCallback(()=>{ce.current=!0,L.current=null,ee(!0),E(!1),h(!0),H(),g()},[g,H,h]),tn=t.useCallback(e=>{if(!p||I){E(!1);return}E(e)},[p,I]),nn=t.useCallback(e=>{const n=d[e]?.audioKey;if(!n||!f||n!==f)return;const o=R.findIndex(u=>u===n);if(o<0){N(null);return}const a=o+1,l=R[a];if(l){N(l);return}if(N(null),Ze(!0),E(!1),x){const u=c+1,y=_[u];dt&&y?.type==="interaction"&&(L.current=u),g()}},[d,x,c,f,R,g,dt,_]),rn=t.useCallback(()=>{s&&pe(e=>!e)},[s]),vt=t.useCallback(e=>{e.stopPropagation(),w&&h(!0)},[Je,h]),sn=t.useCallback(e=>{De?.(e)},[De]),on=t.useCallback(()=>{ee(!0),h(!0)},[h]),Se=t.useMemo(()=>M.map((e,n)=>`${e.sequence_number??`${e.type}-${n}`}:${String(e.is_new??"")}`),[M]);return t.useEffect(()=>{const e=ze.current,a=(e.length>0&&e.length<Se.length&&e.every((u,y)=>u===Se[y])?M.slice(e.length):[]).some(u=>u.is_new===!1);if(ze.current=Se,!a)return;const l=window.requestAnimationFrame(()=>{const u=Ae.current,y=Ue.current;if(!u||!y)return;const ln=u.getBoundingClientRect(),un=y.getBoundingClientRect(),cn=u.scrollTop+(un.top-ln.top);u.scrollTo({top:Math.max(cn,0),behavior:"smooth"})});return()=>{window.cancelAnimationFrame(l)}},[M,Se]),t.useEffect(()=>{if(!ce.current||(ce.current=!1,M.length===0))return;const e=window.requestAnimationFrame(()=>{bt()});return()=>{window.cancelAnimationFrame(e)}},[M,bt]),r.jsxRuntimeExports.jsxs("section",{ref:ie,className:z.cn("relative h-full w-full",A&&"slide--mobile-device",K&&"slide--mobile-landscape",rt&&"slide--mobile-landscape-native",It),onClick:on,onPointerDown:sn,...At,children:[Lt?r.jsxRuntimeExports.jsx("div",{"aria-hidden":"true",className:"pointer-events-none fixed left-0 top-0 z-[9999] h-[100vh] max-h-[100vh] w-[100vw]"}):null,r.jsxRuntimeExports.jsxs("div",{ref:He,className:z.cn("slide__viewport relative h-full min-h-0 w-full",K&&"slide__viewport--mobile-landscape",K&&!Ot&&"slide__viewport--mobile-landscape-native"),children:[qt?r.jsxRuntimeExports.jsxs("div",{className:"slide-landscape-header",children:[r.jsxRuntimeExports.jsx("button",{"aria-label":v?.backAriaLabel??"Back",className:"slide-landscape-header__back",onClick:Kt,type:"button",children:r.jsxRuntimeExports.jsx(In.default,{className:"h-6 w-6 text-white",strokeWidth:2.25})}),v?.content?r.jsxRuntimeExports.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:v.content}):null]}):null,r.jsxRuntimeExports.jsx("div",{className:z.cn("h-full min-h-0 w-full",Bt&&"slide__viewport-content--with-header",Ct?"slide-content--single":"grid gap-4"),children:M.length>0?r.jsxRuntimeExports.jsx("div",{className:"slide-stage",children:r.jsxRuntimeExports.jsx("div",{ref:Ae,className:"slide-stage__layer w-full",children:Ht.map((e,n)=>{const o=n===Ut;return r.jsxRuntimeExports.jsx("div",{"aria-hidden":!o||void 0,className:"w-full h-full",style:{display:o?void 0:"none"},children:Jt(e.elementList,o)},e.sourceStepIndexes[0]??n)})})}):null}),Mt?r.jsxRuntimeExports.jsx(dn.default,{message:ye,className:"absolute left-1/2 top-1/2 z-[3] -translate-x-1/2 -translate-y-1/2"}):null,r.jsxRuntimeExports.jsx(xn.default,{onClose:Dt,open:Ft,text:Nt}),r.jsxRuntimeExports.jsx(pn.default,{extraBottomOffset:Tt,hasPlayerGap:w,isEnabled:et&&_t,isPlayerHidden:S&&!w,playbackTimeStore:V,subtitleCues:Wt}),qe?r.jsxRuntimeExports.jsx("div",{ref:We,className:z.cn("slide-interaction-overlay",w&&S?"slide-interaction-overlay--with-player":"slide-interaction-overlay--standalone"),onClick:vt,onPointerDown:vt,style:zt,children:r.jsxRuntimeExports.jsx(gt,{content:String(s?.content??""),defaultButtonText:mt.buttonText??"",defaultInputText:mt.inputText??"",defaultSelectedValues:$t,confirmButtonText:B?.confirmButtonText,copyButtonText:B?.copyButtonText,copiedButtonText:B?.copiedButtonText,onSend:Yt,readonly:ht,title:B?.title??ge??"Submit the content below to continue."})}):null,S?r.jsxRuntimeExports.jsx(mn.default,{audioList:d,className:z.cn("absolute left-1/2 bottom-6 z-[2] -translate-x-1/2",G,!w&&"pointer-events-none opacity-0"),currentAudioIndex:m,defaultPlaying:!0,isPlaybackPaused:j,isAutoAdvanceEnabled:te,hasInteraction:!!s,isInteractionOpen:me,isSubtitleEnabled:et,onAutoAdvanceToggle:Qe,onLoadingChange:tn,onPlaybackStarted:()=>{we(!0)},onPlaybackTimeChange:V.setTime,onSubtitleToggle:()=>{kt(e=>!e)},nextDisabled:!x,onEnded:nn,onFullscreen:Qt,isFullscreen:jt,mobileViewMode:T,settingsPortalContainer:He.current,onMobileViewModeChange:Vt,onInteractionToggle:rn,onNext:en,onPrev:Zt,prevDisabled:!wt,showControls:w,texts:Be,customActionContext:Fe,customActions:q,useAutoAdvanceToggle:se}):null]})]})};exports.default=kn;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("../../_virtual/jsx-runtime.cjs.js"),t=require("react"),dn=require("../../lib/sandboxInteraction.cjs.js"),G=require("../../lib/utils.cjs.js"),fn=require("../ui/loading-overlay-card.cjs.js"),mn=require("../ContentRender/ContentRender.cjs.js"),St=require("../ContentRender/IframeSandbox.cjs.js");require("../ui/inputGroup/input-group.cjs.js");const yt=require("../../lib/interaction-defaults.cjs.js"),ye=require("../../lib/mobileDevice.cjs.js"),pn=require("./Player.cjs.js"),hn=require("./SubtitleOverlay.cjs.js"),xn=require("./constants.cjs.js"),bn=require("./SlideFullscreenHint.cjs.js"),vn=require("./useSlide.cjs.js"),En=require("./useWakePlayerFromIframe.cjs.js"),ue=require("./utils/mobileScreenMode.cjs.js"),Sn=require("./utils/interactionPlayback.cjs.js"),yn=require("./utils/appendedMarkerAdvance.cjs.js"),gn=require("./utils/playbackSequence.cjs.js"),gt=require("./utils/playerCustomActions.cjs.js"),Rn=require("./utils/playbackTimeStore.cjs.js"),In=require("./utils/playerToggleMode.cjs.js");;/* empty css */const An=require("../../markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/chevron-left.cjs.js"),wn=2e3,Cn=300,Mn=160,_n=16,Rt=t.memo(({content:q,title:B,defaultButtonText:v,defaultInputText:$,defaultSelectedValues:E,confirmButtonText:N,copyButtonText:Y,copiedButtonText:ge,onSend:Re,readonly:O=!1})=>r.jsxRuntimeExports.jsxs("div",{className:"slide-player__interaction-card",children:[r.jsxRuntimeExports.jsx("div",{className:"slide-player__interaction-header",children:r.jsxRuntimeExports.jsx("p",{className:"slide-player__interaction-title",children:B})}),r.jsxRuntimeExports.jsx("div",{className:"slide-player__interaction-body",children:r.jsxRuntimeExports.jsx(mn.default,{content:q,defaultButtonText:v,defaultInputText:$,defaultSelectedValues:E,confirmButtonText:N,copyButtonText:Y,copiedButtonText:ge,onSend:Re,readonly:O,enableTypewriter:!1,sandboxMode:"content"})})]}));Rt.displayName="InteractionOverlayCard";const kn=(q,B)=>q.length===B.length&&q.every((v,$)=>{const E=B[$];return v.sequence_number===E?.sequence_number&&v.type===E?.type&&v.content===E?.content}),Tn=({elementList:q=[],showPlayer:B=!0,playerAlwaysVisible:v=!1,playerClassName:$,fullscreenHeader:E,playerCustomActions:N,playerCustomActionPauseOnActive:Y=!0,bufferingText:ge="Buffering...",interactionTitle:Re,interactionTexts:O,playerTexts:Oe,playerAutoHideDelay:Ie=3e3,markerAutoAdvanceDelay:Le=wn,interactionDefaultValueOptions:ie,onSend:Ve,onPlayerVisibilityChange:Ae,onMobileViewModeChange:Ke,onStepChange:De,enableIframeScaling:It=!0,disableLoadingOverlay:g=!1,className:At,onPointerDown:He,...wt})=>{const ce=t.useRef(null),Ue=t.useRef(null),we=t.useRef(null),We=t.useRef(null),X=t.useRef(null),J=t.useRef(null),Q=t.useRef(null),Z=t.useRef(null),ze=t.useRef(null),Ge=t.useRef([]),ae=t.useRef(!1),L=t.useRef(null),$e=t.useRef(null),Ye=t.useRef({markerCount:0,currentIndex:-1,canGoNext:!1}),{currentElementList:_,stepElementLists:Xe,slideElementList:k,currentIndex:c,audioList:d,currentAudioSequenceIndexes:de,currentStepHasSpeakableElement:h,currentInteractionElement:i,canGoPrev:Ct,canGoNext:b,handlePrev:Je,handleNext:R}=vn.default(q),ee=t.useMemo(()=>{if(!(c<0))return k[c]},[c,k]),Mt=k.filter(e=>e.is_renderable!==!1).length===1,S=B&&(k.length>0||d.length>0||!!i),I=t.useMemo(()=>de.map(e=>d[e]?.audioKey).filter(e=>!!e),[d,de]),[Qe,fe]=t.useState(!0),[me,te]=t.useState(!1),[ne,Ze]=t.useState(!0),[f,V]=t.useState(null),[_t,m]=t.useState(!1),[A,et]=t.useState(!1),[kt,Ce]=t.useState(!1),[tt,Tt]=t.useState(!0),[Me,_e]=t.useState(!1),[s,ke]=t.useState(),[pe,he]=t.useState(!1),[jt,re]=t.useState(0),[Pt,Ft]=t.useState(!1),w=t.useMemo(()=>ye.isMobileDevice(),[]),[xe,Te]=t.useState(ue.DEFAULT_MOBILE_VIEW_MODE),[nt,je]=t.useState(!1),[Pe,rt]=t.useState(()=>w?ye.isLandscapeViewport():!1),[qt,be]=t.useState(!1),K=t.useMemo(()=>Rn.createPlaybackTimeStore(),[]),{effectiveMobileViewMode:j,isImmersiveMobileFullscreen:D,isNativeMobileFullscreen:st,shouldRotateFullscreenViewport:Bt}=t.useMemo(()=>ue.resolveMobileViewModeState({hasManualMobileViewMode:nt,isMobileDevice:w,mobileViewMode:xe}),[nt,w,Pe,xe]),ot=t.useRef(j),C=S&&(v||Qe),Nt=D&&C,Ot=D&&C,Lt=D||st,Vt=Oe?.fullscreenHintText??xn.DEFAULT_SLIDE_PLAYER_TEXTS.fullscreenHintText,Kt=t.useCallback(e=>{je(!0),Te(e)},[]),lt=t.useCallback(()=>{je(!1),Te(ue.DEFAULT_MOBILE_VIEW_MODE)},[]),Dt=t.useCallback(()=>{lt(),E?.onBack?.()},[E,lt]),Ht=t.useCallback(()=>{be(!1)},[]),ut=t.useCallback(e=>{_e(e)},[]),it=t.useCallback(()=>{_e(e=>!e)},[]),{mountedStepStates:Ut,currentMountedStateIndex:Wt}=t.useMemo(()=>{const e=[],n=new Map;return Xe.forEach((o,a)=>{const l=e.findIndex(u=>kn(u.elementList,o));if(l>=0){e[l]?.sourceStepIndexes.push(a),n.set(a,l);return}e.push({elementList:o,sourceStepIndexes:[a]}),n.set(a,e.length-1)}),{mountedStepStates:e,currentMountedStateIndex:c>=0?n.get(c)??-1:-1}},[c,Xe]),ct=t.useMemo(()=>String(c),[c]),p=t.useMemo(()=>f?d.findIndex(e=>(e.audioKey??"")===f):-1,[d,f]),Fe=t.useMemo(()=>p>=0?d[p]:void 0,[d,p]),zt=Fe?.element?.subtitle_cues??[],ve=t.useMemo(()=>I[0]??"none",[I]),qe=t.useMemo(()=>({currentElement:gt.resolvePlayerCustomActionElement({currentAudioIndex:p,currentAudioSequenceIndexes:de,audioList:d,currentInteractionElement:s,currentStepElement:ee}),currentIndex:c,currentStepElement:ee,isActive:Me,setActive:ut,toggleActive:it}),[s,d,p,de,c,ee,Me,ut,it]),Be=t.useMemo(()=>gt.getPlayerCustomActionCount(N,qe),[qe,N]),Gt=t.useMemo(()=>({"--slide-player-custom-action-count":String(Be),"--slide-player-mobile-control-count":String(Be+4)}),[Be]),at=I.length>0,dt=t.useMemo(()=>i?`${i.sequence_number??"none"}:${String(i.content??"")}`:"none",[i]),se=t.useMemo(()=>[ct,dt].join("|"),[dt,ct]),$t=t.useMemo(()=>[se,Fe?.audioKey??"none",String(p)].join("|"),[p,Fe?.audioKey,se]),ft=!!t.useMemo(()=>!ve||ve==="none"?"":d.find(n=>n.audioKey===ve)?.audioUrl?.trim()??"",[d,ve]),P=Y&&!!N&&Me,oe=t.useMemo(()=>In.shouldUseAutoAdvanceToggle({canGoNext:b,currentAudioIndex:p,currentStepHasSpeakableElement:h,hasInteraction:!!i}),[b,p,i,h]),F=t.useCallback(()=>{X.current!==null&&(window.clearTimeout(X.current),X.current=null)},[]),T=t.useCallback(()=>{Q.current!==null&&(window.clearTimeout(Q.current),Q.current=null)},[]),M=t.useCallback(()=>{Z.current!==null&&(window.clearTimeout(Z.current),Z.current=null)},[]),H=t.useCallback(()=>{J.current!==null&&(window.clearTimeout(J.current),J.current=null)},[]),U=t.useCallback(()=>{H(),T(),M(),V(null),K.reset(),m(!1),et(!1),Ce(!1),ke(void 0),he(!1),re(0)},[H,T,M,K]),W=t.useCallback(()=>{const e=I[0];return e?(V(e),!0):!1},[I]),Ee=t.useCallback(()=>{T(),M(),he(!1),re(0),!W()&&b&&R()},[b,T,M,R,W]),mt=t.useCallback(e=>{if(M(),!e)return;const n=()=>{Z.current=null,re(Mn),he(!0),L.current=null};Z.current=window.setTimeout(n,Cn)},[M]),x=t.useCallback((e=me)=>{S&&(fe(!0),F(),!(v||!e||Ie<=0)&&(X.current=window.setTimeout(()=>{fe(!1),X.current=null},Ie)))},[F,me,v,Ie,S]),le=!!(i?.readonly||i?.user_input?.trim()),z=!!i&&!le;t.useEffect(()=>{Ze(!0),Y&&_e(!1)},[c,Y]),t.useEffect(()=>()=>{H(),F(),T(),M()},[H,T,M,F]),t.useEffect(()=>(Ae?.(C),()=>{Ae?.(!1)}),[Ae,C]),t.useEffect(()=>{w||xe===ue.DEFAULT_MOBILE_VIEW_MODE||(je(!1),Te(ue.DEFAULT_MOBILE_VIEW_MODE))},[w,xe]),t.useEffect(()=>{if(!w){rt(!1);return}const e=()=>{rt(ye.isLandscapeViewport())};return e(),ye.subscribeMobileDeviceChange(e)},[w]),t.useEffect(()=>{Ke?.(j)},[j,Ke]),t.useEffect(()=>{const o=ot.current!=="fullscreen"&&j==="fullscreen"&&!Pe;if(ot.current=j,!w){be(!1);return}if(o){be(!0);return}j!=="fullscreen"&&be(!1)},[j,w,Pe]),t.useEffect(()=>{De?.(ee,c)},[c,ee,De]),t.useEffect(()=>{const e=Ye.current,n=yn.shouldAutoAdvanceIntoAppendedMarker({previousMarkerCount:e.markerCount,nextMarkerCount:k.length,previousIndex:e.currentIndex,previousCanGoNext:e.canGoNext,nextCanGoNext:b,currentAudioKey:f,hasCompletedCurrentStepAudio:A,hasResolvedCurrentInteraction:le,currentStepHasSpeakableElement:h,currentInteractionElement:i,isAutoAdvanceEnabled:ne,shouldUseSilentStepAutoAdvanceToggle:oe});Ye.current={markerCount:k.length,currentIndex:c,canGoNext:b},n&&R()},[b,f,c,i,h,R,A,le,ne,oe,k.length]),t.useEffect(()=>{if(!S){F(),fe(!1);return}if(v){F(),fe(!0);return}me||x(!0)},[F,me,v,S,x]),t.useEffect(()=>{if(typeof window>"u")return;const e=n=>{n.origin===window.location.origin&&dn.isSandboxInteractionMessage(n.data)&&n.data.eventType==="click"&&S&&(te(!0),x(!0))};return window.addEventListener("message",e),()=>{window.removeEventListener("message",e)}},[S,x]),En.default({sectionRef:ce,enabled:S,onWake:()=>{te(!0),x(!0)}}),t.useEffect(()=>{const{hasPlaybackContextChanged:e,shouldInitializeAudioSequence:n}=gn.getPlaybackSequenceTransition({previousResetKey:$e.current,nextResetKey:se,currentAudioKey:f,hasCompletedCurrentStepAudio:A});$e.current=se;const o=L.current===c&&!!i,a=Sn.shouldPresentInteractionOverlay({hasInteraction:!!i,shouldBlockPlaybackForInteraction:z,shouldOpenInteractionOverlayAfterAudio:o,hasPlaybackContextChanged:e,hasResolvedCurrentInteraction:le,currentStepHasSpeakableElement:h});if(e&&U(),!(_.length===0&&!i)&&!P){if(i&&ke(i),a){mt(i);return}if(M(),L.current=null,!!n&&!W()){if(h){if(g){m(!1);return}m(!0);return}if(b&&!(oe&&!ne))return J.current=window.setTimeout(()=>{J.current=null,R()},Le),()=>{H()}}}},[b,H,_.length,i,f,se,h,Le,R,A,g,ne,le,z,M,U,mt,W,P,oe]),t.useEffect(()=>{if(g||P||!h||z){m(!1);return}if(A){m(!1);return}if(at){m(!1);return}m(!0)},[at,h,A,g,P,z]),t.useEffect(()=>{f||I.length===0||P||!h||z||A||W()},[f,I,h,A,P,z,W]),t.useEffect(()=>{!f||p>=0||V(null)},[p,f]),t.useEffect(()=>{p>=0||K.reset()},[p,K]),t.useEffect(()=>{Ce(!1)},[$t]);const pt=t.useMemo(()=>{if(!s)return{};const e=!!s.user_input?.trim();return yt.getInteractionDefaultValues(typeof s.content=="string"?s.content:void 0,s.user_input,e?void 0:ie)},[s,ie]),Yt=t.useMemo(()=>{if(!s)return;const e=!!s.user_input?.trim();return yt.getInteractionDefaultSelectedValues(typeof s.content=="string"?s.content:void 0,s.user_input,e?void 0:ie)},[s,ie]),ht=!!s?.user_input?.trim(),xt=!!s?.readonly||ht,bt=xt||ht,Ne=!!s&&pe,Xt=t.useCallback(e=>{const o=[...e.selectedValues??[],e.inputText?.trim()??"",e.buttonText?.trim()??""].filter(Boolean).join(", ");ke(a=>!a||!o?a:{...a,user_input:o}),Ve?.(e,s),Ee()},[s,Ee,Ve]);t.useEffect(()=>{const e=()=>{Ft(document.fullscreenElement===ce.current)};return e(),document.addEventListener("fullscreenchange",e),()=>{document.removeEventListener("fullscreenchange",e)}},[]),t.useEffect(()=>{if(!Ne){re(0);return}const e=ze.current;if(!e)return;const n=()=>{const a=Math.ceil(e.getBoundingClientRect().height);re(a+_n)};if(n(),typeof ResizeObserver>"u")return;const o=new ResizeObserver(()=>{n()});return o.observe(e),()=>{o.disconnect()}},[Ne]),t.useEffect(()=>{if(T(),!(!pe||!bt))return Q.current=window.setTimeout(()=>{Q.current=null,Ee()},2e3),()=>{T()}},[T,Ee,pe,bt]);const Jt=(e,n={})=>e?e.type==="slot"?r.jsxRuntimeExports.jsx(r.jsxRuntimeExports.Fragment,{children:e.content}):e.type==="html"?r.jsxRuntimeExports.jsx(St.default,{className:"content-render-iframe",disableLoadingOverlay:g,hideFullScreen:!0,mode:"blackboard",replaceRootScreenHeightWithFull:n.replaceRootScreenHeightWithFull,type:"sandbox",content:e.content,enableScaling:It}):r.jsxRuntimeExports.jsx(St.default,{className:"content-render-iframe",disableLoadingOverlay:g,hideFullScreen:!0,mode:"blackboard",type:"markdown",content:e.content}):null,Qt=(e=[],n=!1)=>{if(e.length===0)return null;const o=e.filter(l=>l.is_renderable!==!1).length,a=e.reduce((l,u,y)=>u.is_renderable!==!1?y:l,-1);return r.jsxRuntimeExports.jsx("div",{className:"slide-stage__content flex w-full flex-col gap-4",children:e.map((l,u)=>{const y=l.type==="html"&&l.is_renderable===!1;return r.jsxRuntimeExports.jsx("div",{ref:n&&u===a?We:null,"aria-hidden":y||void 0,className:G.cn("w-full shrink-0",o===1&&l.is_renderable!==!1&&"slide-element--single",y?"pointer-events-none fixed left-[-200vw] top-0 -z-10 h-[100dvh] w-[100vw] overflow-hidden opacity-0":l.is_renderable===!1&&"hidden"),children:Jt(l,{replaceRootScreenHeightWithFull:o===1&&l.type==="html"&&l.is_renderable!==!1})},l.sequence_number??`${l.type}-${u}`)})})},Zt=t.useCallback(()=>{const e=ce.current;if(e){if(document.fullscreenElement===e){document.exitFullscreen().catch(()=>{});return}e.requestFullscreen?.().catch(()=>{})}},[]),vt=t.useCallback(()=>{const e=we.current;e&&e.scrollTo({top:e.scrollHeight,behavior:"smooth"})},[]),en=t.useCallback(()=>{ae.current=!0,L.current=null,te(!0),m(!1),x(!0),U(),Je()},[Je,U,x]),tn=t.useCallback(()=>{ae.current=!0,L.current=null,te(!0),m(!1),x(!0),U(),R()},[R,U,x]),nn=t.useCallback(e=>{if(g){m(!1);return}if(!h||A){m(!1);return}m(e)},[h,A,g]);t.useEffect(()=>{g&&m(!1)},[g]);const rn=t.useCallback(e=>{const n=d[e]?.audioKey;if(!n||!f||n!==f)return;const o=I.findIndex(u=>u===n);if(o<0){V(null);return}const a=o+1,l=I[a];if(l){V(l);return}if(V(null),et(!0),m(!1),b){const u=c+1,y=k[u];ft&&y?.type==="interaction"&&(L.current=u),R()}},[d,b,c,f,I,R,ft,k]),sn=t.useCallback(()=>{s&&he(e=>!e)},[s]),Et=t.useCallback(e=>{e.stopPropagation(),C&&x(!0)},[Qe,x]),on=t.useCallback(e=>{He?.(e)},[He]),ln=t.useCallback(()=>{te(!0),x(!0)},[x]),Se=t.useMemo(()=>_.map((e,n)=>`${e.sequence_number??`${e.type}-${n}`}:${String(e.is_new??"")}`),[_]);return t.useEffect(()=>{const e=Ge.current,a=(e.length>0&&e.length<Se.length&&e.every((u,y)=>u===Se[y])?_.slice(e.length):[]).some(u=>u.is_new===!1);if(Ge.current=Se,!a)return;const l=window.requestAnimationFrame(()=>{const u=we.current,y=We.current;if(!u||!y)return;const un=u.getBoundingClientRect(),cn=y.getBoundingClientRect(),an=u.scrollTop+(cn.top-un.top);u.scrollTo({top:Math.max(an,0),behavior:"smooth"})});return()=>{window.cancelAnimationFrame(l)}},[_,Se]),t.useEffect(()=>{if(!ae.current||(ae.current=!1,_.length===0))return;const e=window.requestAnimationFrame(()=>{vt()});return()=>{window.cancelAnimationFrame(e)}},[_,vt]),r.jsxRuntimeExports.jsxs("section",{ref:ce,className:G.cn("relative h-full w-full",w&&"slide--mobile-device",D&&"slide--mobile-landscape",st&&"slide--mobile-landscape-native",At),onClick:ln,onPointerDown:on,...wt,children:[Lt?r.jsxRuntimeExports.jsx("div",{"aria-hidden":"true",className:"pointer-events-none fixed left-0 top-0 z-[9999] h-[100vh] max-h-[100vh] w-[100vw]"}):null,r.jsxRuntimeExports.jsxs("div",{ref:Ue,className:G.cn("slide__viewport relative h-full min-h-0 w-full",D&&"slide__viewport--mobile-landscape",D&&!Bt&&"slide__viewport--mobile-landscape-native"),children:[Nt?r.jsxRuntimeExports.jsxs("div",{className:"slide-landscape-header",children:[r.jsxRuntimeExports.jsx("button",{"aria-label":E?.backAriaLabel??"Back",className:"slide-landscape-header__back",onClick:Dt,type:"button",children:r.jsxRuntimeExports.jsx(An.default,{className:"h-6 w-6 text-white",strokeWidth:2.25})}),E?.content?r.jsxRuntimeExports.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:E.content}):null]}):null,r.jsxRuntimeExports.jsx("div",{className:G.cn("h-full min-h-0 w-full",Ot&&"slide__viewport-content--with-header",Mt?"slide-content--single":"grid gap-4"),children:_.length>0?r.jsxRuntimeExports.jsx("div",{className:"slide-stage",children:r.jsxRuntimeExports.jsx("div",{ref:we,className:"slide-stage__layer w-full",children:Ut.map((e,n)=>{const o=n===Wt;return r.jsxRuntimeExports.jsx("div",{"aria-hidden":!o||void 0,className:"w-full h-full",style:{display:o?void 0:"none"},children:Qt(e.elementList,o)},e.sourceStepIndexes[0]??n)})})}):null}),_t?r.jsxRuntimeExports.jsx(fn.default,{message:ge,className:"absolute left-1/2 top-1/2 z-[3] -translate-x-1/2 -translate-y-1/2"}):null,r.jsxRuntimeExports.jsx(bn.default,{onClose:Ht,open:qt,text:Vt}),r.jsxRuntimeExports.jsx(hn.default,{extraBottomOffset:jt,hasPlayerGap:C,isEnabled:tt&&kt,isPlayerHidden:S&&!C,playbackTimeStore:K,subtitleCues:zt}),Ne?r.jsxRuntimeExports.jsx("div",{ref:ze,className:G.cn("slide-interaction-overlay",C&&S?"slide-interaction-overlay--with-player":"slide-interaction-overlay--standalone"),onClick:Et,onPointerDown:Et,style:Gt,children:r.jsxRuntimeExports.jsx(Rt,{content:String(s?.content??""),defaultButtonText:pt.buttonText??"",defaultInputText:pt.inputText??"",defaultSelectedValues:Yt,confirmButtonText:O?.confirmButtonText,copyButtonText:O?.copyButtonText,copiedButtonText:O?.copiedButtonText,onSend:Xt,readonly:xt,title:O?.title??Re??"Submit the content below to continue."})}):null,S?r.jsxRuntimeExports.jsx(pn.default,{audioList:d,className:G.cn("absolute left-1/2 bottom-6 z-[2] -translate-x-1/2",$,!C&&"pointer-events-none opacity-0"),currentAudioIndex:p,defaultPlaying:!0,isPlaybackPaused:P,isAutoAdvanceEnabled:ne,hasInteraction:!!s,isInteractionOpen:pe,isSubtitleEnabled:tt,onAutoAdvanceToggle:Ze,onLoadingChange:nn,onPlaybackStarted:()=>{Ce(!0)},onPlaybackTimeChange:K.setTime,onSubtitleToggle:()=>{Tt(e=>!e)},nextDisabled:!b,onEnded:rn,onFullscreen:Zt,isFullscreen:Pt,mobileViewMode:j,settingsPortalContainer:Ue.current,onMobileViewModeChange:Kt,onInteractionToggle:sn,onNext:tn,onPrev:en,prevDisabled:!Ct,showControls:C,texts:Oe,customActionContext:qe,customActions:N,useAutoAdvanceToggle:oe}):null]})]})};exports.default=Tn;
|
|
2
2
|
//# sourceMappingURL=Slide.cjs.js.map
|