markdown-flow-ui 0.1.112-beta.1 → 0.1.112-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/_virtual/index.cjs10.js +1 -1
  2. package/dist/_virtual/index.cjs4.js +1 -1
  3. package/dist/_virtual/index.cjs5.js +1 -1
  4. package/dist/_virtual/index.cjs6.js +1 -1
  5. package/dist/_virtual/index.cjs7.js +1 -1
  6. package/dist/_virtual/index.cjs8.js +1 -1
  7. package/dist/_virtual/index.cjs9.js +1 -1
  8. package/dist/_virtual/index.es10.js +2 -2
  9. package/dist/_virtual/index.es4.js +4 -4
  10. package/dist/_virtual/index.es5.js +4 -4
  11. package/dist/_virtual/index.es6.js +5 -2
  12. package/dist/_virtual/index.es6.js.map +1 -1
  13. package/dist/_virtual/index.es7.js +2 -5
  14. package/dist/_virtual/index.es7.js.map +1 -1
  15. package/dist/_virtual/index.es8.js +2 -3
  16. package/dist/_virtual/index.es8.js.map +1 -1
  17. package/dist/_virtual/index.es9.js +3 -2
  18. package/dist/_virtual/index.es9.js.map +1 -1
  19. package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
  20. package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
  21. package/dist/components/ContentRender/ContentRender.d.ts +1 -0
  22. package/dist/components/ContentRender/ContentRender.es.js +118 -116
  23. package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
  24. package/dist/components/ContentRender/IframeSandbox.cjs.js +2 -2
  25. package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
  26. package/dist/components/ContentRender/IframeSandbox.d.ts +1 -0
  27. package/dist/components/ContentRender/IframeSandbox.es.js +108 -100
  28. package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
  29. package/dist/components/ContentRender/SandboxApp.cjs.js +2 -2
  30. package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
  31. package/dist/components/ContentRender/SandboxApp.d.ts +1 -0
  32. package/dist/components/ContentRender/SandboxApp.es.js +90 -87
  33. package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
  34. package/dist/components/Slide/Slide.cjs.js +1 -1
  35. package/dist/components/Slide/Slide.cjs.js.map +1 -1
  36. package/dist/components/Slide/Slide.d.ts +1 -8
  37. package/dist/components/Slide/Slide.es.js +603 -696
  38. package/dist/components/Slide/Slide.es.js.map +1 -1
  39. package/dist/components/Slide/Slide.stories.d.ts +0 -12
  40. package/dist/components/Slide/constants.cjs.js +1 -1
  41. package/dist/components/Slide/constants.cjs.js.map +1 -1
  42. package/dist/components/Slide/constants.d.ts +0 -4
  43. package/dist/components/Slide/constants.es.js +2 -6
  44. package/dist/components/Slide/constants.es.js.map +1 -1
  45. package/dist/components/Slide/index.d.ts +1 -2
  46. package/dist/components/index.d.ts +2 -2
  47. package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
  48. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  49. package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js +1 -1
  50. package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js.map +1 -1
  51. package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
  52. package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
  53. package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
  54. package/dist/markdown-flow-ui/node_modules/.pnpm/hast-util-to-jsx-runtime@2.3.6/node_modules/hast-util-to-jsx-runtime/lib/index.cjs.js +1 -1
  55. package/dist/markdown-flow-ui/node_modules/.pnpm/hast-util-to-jsx-runtime@2.3.6/node_modules/hast-util-to-jsx-runtime/lib/index.es.js +1 -1
  56. 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
  57. 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
  58. 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
  59. 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
  60. 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
  61. 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
  62. 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
  63. 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
  64. 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
  65. 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
  66. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.cjs.js +1 -1
  67. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.es.js +1 -1
  68. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.cjs.js +1 -1
  69. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
  70. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js +1 -1
  71. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js +1 -1
  72. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.cjs.js +1 -1
  73. package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.es.js +1 -1
  74. package/dist/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.cjs.js +1 -1
  75. package/dist/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.es.js +1 -1
  76. package/dist/markdown-flow-ui/node_modules/.pnpm/unified@11.0.5/node_modules/unified/lib/index.cjs.js +1 -1
  77. package/dist/markdown-flow-ui/node_modules/.pnpm/unified@11.0.5/node_modules/unified/lib/index.es.js +1 -1
  78. package/dist/markdown-flow-ui-lib.css +1 -1
  79. package/dist/slide.cjs.js +1 -1
  80. package/dist/slide.es.js +4 -6
  81. package/dist/slide.es.js.map +1 -1
  82. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
- import { j as C } from "../../_virtual/jsx-runtime.es.js";
2
- import { useRef as i, useState as H, useEffect as L } from "react";
3
- import X from "../ui/loading-overlay-card.es.js";
4
- const Y = [
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
- ], V = (c) => Y.map(
18
+ ], W = (c) => Z.map(
19
19
  (t) => `${t}:${c.getAttribute(t) || ""}`
20
- ).join("|"), Z = (c) => {
20
+ ).join("|"), ee = (c) => {
21
21
  const t = /* @__PURE__ */ new Map();
22
- return c.querySelectorAll("img").forEach((u) => {
23
- const o = u, n = V(o), f = t.get(n) || [];
24
- f.push(o), t.set(n, f);
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
- }, ee = (c, t) => {
27
- const u = Array.from(c.attributes), o = new Set(
28
- u.map((n) => n.name)
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
- }), u.forEach((n) => {
32
+ }), f.forEach((n) => {
33
33
  t.setAttribute(n.name, n.value);
34
34
  });
35
- }, te = (c, t) => {
36
- t.size && c.querySelectorAll("img").forEach((u) => {
37
- const o = u, n = V(o), f = t.get(n), h = f?.shift();
38
- h && (ee(o, h), o.replaceWith(h), f && f.length === 0 && t.delete(n));
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
- }, ae = ({
40
+ }, ie = ({
41
41
  html: c,
42
42
  styleLoadingText: t,
43
- scriptLoadingText: u,
43
+ scriptLoadingText: f,
44
44
  resetToken: o = 0,
45
45
  mode: n = "content",
46
- hasRootVhHeight: f = !1,
46
+ hasRootVhHeight: m = !1,
47
47
  stretchRootHeight: h = !1,
48
- enableScaling: M = !1
48
+ enableScaling: G = !1,
49
+ disableLoadingOverlay: N = !1
49
50
  }) => {
50
- const A = i(null), [W, R] = H(!1), [O, I] = H(!1), N = i([]), j = i([]), D = i(0), G = i(0), g = i(null), x = i(null), v = i(!1), b = i(!1), k = i(!1), B = i(o), U = 200, d = (r) => {
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
- }, F = (r, a, l, _) => {
53
- const m = performance.now() - l.current, S = Math.max(0, U - m);
54
- d(a), a.current = window.setTimeout(() => {
55
- r(!1), _?.(), a.current = null;
56
- }, S);
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
- L(() => {
59
- const r = A.current?.ownerDocument;
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
- }, []), L(() => {
74
- o !== B.current && (k.current = !1, B.current = o), d(g), d(x), v.current = !1, b.current = !1;
75
- const r = A.current;
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 _ = Z(r);
80
- N.current.forEach((e) => e.remove()), N.current = [], j.current.forEach((e) => e.remove()), j.current = [], R(!1), I(!1);
81
- const m = a.createElement("div");
82
- m.innerHTML = c;
83
- const S = (c.match(/<script[\s>]/gi) || []).length, Q = (c.match(/<\/script>/gi) || []).length, J = S > 0 && S === Q, y = [];
84
- Array.from(m.querySelectorAll("style, script")).forEach((e) => {
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((p) => {
88
- s.setAttribute(p.name, p.value);
89
- }), y.push(s);
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((p) => {
93
- s.setAttribute(p.name, p.value);
94
- }), s.textContent = e.textContent || "", y.push(s);
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
- }), te(m, _);
98
- const q = y.some(
98
+ }), re(p, D);
99
+ const z = b.some(
99
100
  (e) => e.tagName.toLowerCase() === "style"
100
- ), z = y.some(
101
+ ), H = b.some(
101
102
  (e) => e.tagName.toLowerCase() === "script"
102
103
  );
103
- q && (v.current = !0, D.current = performance.now(), d(g), R(!0)), z && (b.current = !0, G.current = performance.now(), d(x), I(!0)), !!m.firstElementChild && (k.current = !0);
104
- const P = Array.from(m.childNodes);
105
- r.replaceChildren(...P), y.forEach((e) => {
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), N.current.push(e);
108
+ a.head?.appendChild(e), T.current.push(e);
108
109
  return;
109
110
  }
110
- if (J) {
111
- const s = e, p = s.textContent || "";
111
+ if (P) {
112
+ const s = e, d = s.textContent || "";
112
113
  if (!s.src)
113
114
  try {
114
- new Function(p);
115
+ new Function(d);
115
116
  } catch {
116
117
  s.remove();
117
118
  return;
118
119
  }
119
120
  try {
120
- l.appendChild(s), j.current.push(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
- }), M && r.ownerDocument?.defaultView?.__mdf_triggerFitContent?.(), requestAnimationFrame(() => {
127
- q && F(
128
- R,
129
- g,
130
- D,
127
+ }), G && r.ownerDocument?.defaultView?.__mdf_triggerFitContent?.(), requestAnimationFrame(() => {
128
+ z && q(
129
+ E,
130
+ y,
131
+ k,
131
132
  () => {
132
- v.current = !1;
133
+ x.current = !1;
133
134
  }
134
- ), z && F(
135
- I,
136
- x,
137
- G,
135
+ ), H && q(
136
+ w,
137
+ g,
138
+ B,
138
139
  () => {
139
- b.current = !1;
140
+ v.current = !1;
140
141
  }
141
142
  );
142
143
  });
143
- }, [c, o, M]), L(
144
+ }, [c, o, G]), I(
144
145
  () => () => {
145
- d(g), d(x);
146
+ u(y), u(g);
146
147
  },
147
148
  []
148
- );
149
- const E = O || b.current ? u || "Building scripts cache..." : W || v.current ? t || "Building styles..." : null, T = n === "blackboard", w = T && h, $ = {
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: w ? "flex-start" : T ? "space-around" : "flex-start"
157
- }, K = {
158
- pointerEvents: E ? "none" : void 0,
159
- margin: T ? void 0 : "auto 0",
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: w ? "100%" : void 0,
162
- minHeight: w ? 0 : void 0,
163
- flex: w ? "1 1 auto" : void 0
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__ */ C.jsxs(
168
+ return /* @__PURE__ */ R.jsxs(
166
169
  "div",
167
170
  {
168
- "data-root-vh": f ? "true" : "false",
171
+ "data-root-vh": m ? "true" : "false",
169
172
  className: "sandbox-wrapper",
170
- style: $,
171
- "aria-busy": !!E,
173
+ style: Q,
174
+ "aria-busy": !!S,
172
175
  children: [
173
- /* @__PURE__ */ C.jsx(
176
+ /* @__PURE__ */ R.jsx(
174
177
  "div",
175
178
  {
176
- ref: A,
179
+ ref: j,
177
180
  className: "sandbox-container",
178
- style: K
181
+ style: J
179
182
  }
180
183
  ),
181
- E && /* @__PURE__ */ C.jsx(
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__ */ C.jsx(X, { message: E })
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
- ae as default
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;AACF,GAEMC,IAAmB,CAACC,MACxBF,EAAuB;AAAA,EACrB,CAACG,MAAc,GAAGA,CAAS,IAAID,EAAM,aAAaC,CAAS,KAAK,EAAE;AACpE,EAAE,KAAK,GAAG,GAENC,IAAwB,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,GAA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AAA,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,E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/C,UAAU;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,SAAS;AAAA,IACT,eAAe;AAAA;AAAA,IAEf,gBAAgBD,IACZ,eACAD,IACE,iBACA;AAAA,EAAA,GAEFG,IAA6C;AAAA,IACjD,eAAeJ,IAAiB,SAAS;AAAA,IACzC,QAAQC,IAAe,SAAY;AAAA,IACnC,OAAO;AAAA,IACP,QAAQC,IAA0B,SAAS;AAAA,IAC3C,WAAWA,IAA0B,IAAI;AAAA,IACzC,MAAMA,IAA0B,aAAa;AAAA,EAAA;AAG/C,SACEG,gBAAAA,EAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,gBAAcvD,IAAkB,SAAS;AAAA,MACzC,WAAU;AAAA,MACV,OAAOqD;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,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("../../_virtual/jsx-runtime.cjs.js"),e=require("react"),Rn=require("../../lib/sandboxInteraction.cjs.js"),Y=require("../../lib/utils.cjs.js"),An=require("../ui/loading-overlay-card.cjs.js"),In=require("../ContentRender/ContentRender.cjs.js"),kt=require("../ContentRender/IframeSandbox.cjs.js");require("../ui/inputGroup/input-group.cjs.js");const jt=require("../../lib/interaction-defaults.cjs.js"),_e=require("../../lib/mobileDevice.cjs.js"),_n=require("./Player.cjs.js"),wn=require("./SubtitleOverlay.cjs.js"),ze=require("./constants.cjs.js"),Cn=require("./SlideFullscreenHint.cjs.js"),Tn=require("./useSlide.cjs.js"),Mn=require("./useWakePlayerFromIframe.cjs.js"),de=require("./utils/mobileScreenMode.cjs.js"),kn=require("./utils/interactionPlayback.cjs.js"),jn=require("./utils/appendedMarkerAdvance.cjs.js"),Pn=require("./utils/playbackSequence.cjs.js"),Pt=require("./utils/playerCustomActions.cjs.js"),On=require("./utils/playbackTimeStore.cjs.js"),Fn=require("./utils/playerToggleMode.cjs.js");;/* empty css */const qn=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"),Bn=2e3,Nn=300,Ln=160,Vn=16,Ot=e.memo(({content:o,title:s,defaultButtonText:C,defaultInputText:T,defaultSelectedValues:q,confirmButtonText:B,copyButtonText:V,copiedButtonText:X,onSend:we,readonly:Ce=!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:s})}),r.jsxRuntimeExports.jsx("div",{className:"slide-player__interaction-body",children:r.jsxRuntimeExports.jsx(In.default,{content:o,defaultButtonText:C,defaultInputText:T,defaultSelectedValues:q,confirmButtonText:B,copyButtonText:V,copiedButtonText:X,onSend:we,readonly:Ce,enableTypewriter:!1,sandboxMode:"content"})})]}));Ot.displayName="InteractionOverlayCard";const Kn=(o,s)=>o.length===s.length&&o.every((C,T)=>{const q=s[T];return C.sequence_number===q?.sequence_number&&C.type===q?.type&&C.content===q?.content}),Dn=o=>typeof o=="string"?`string:${o.length}:${o.slice(-32)}`:typeof o=="number"||typeof o=="boolean"?`primitive:${String(o)}`:e.isValidElement(o)?`element:${String(o.key??"")}`:Array.isArray(o)?`array:${o.length}`:o==null?"null":`object:${typeof o}`,Un=o=>(o??[]).map(s=>[String(s.segment_index??"none"),s.is_final?"1":"0",String(s.duration_ms??0),String(s.audio_url??""),String(s.audio_data?.length??0)].join(":")).join(","),Hn=o=>o.map((s,C)=>[String(s.sequence_number??C),String(s.type),Dn(s.content),String(s.audio_url??""),Un(s.audio_segments),s.is_renderable===!1?"hidden":"visible",s.is_new?"new":"stable",s.is_speakable?"speakable":"silent",String(s.user_input??""),s.readonly?"readonly":"editable"].join("|")).join("||"),$n=({elementList:o=[],isStreaming:s=!1,showPlayer:C=!0,playerAlwaysVisible:T=!1,playerClassName:q,fullscreenHeader:B,playerCustomActions:V,playerCustomActionPauseOnActive:X=!0,bufferingText:we="Buffering...",interactionTitle:Ce,interactionTexts:fe,playerTexts:Ge,playerAutoHideDelay:Te=3e3,markerAutoAdvanceDelay:Ye=Bn,streamInactivityTimeoutMs:Me=ze.DEFAULT_STREAM_INACTIVITY_TIMEOUT_MS,interactionDefaultValueOptions:me,onSend:Xe,onPlayerVisibilityChange:ke,onMobileViewModeChange:Je,onError:Qe,onStepChange:Ze,enableIframeScaling:Ft=!0,className:qt,onPointerDown:et,...Bt})=>{const pe=e.useRef(null),tt=e.useRef(null),je=e.useRef(null),nt=e.useRef(null),J=e.useRef(null),Q=e.useRef(null),Z=e.useRef(null),ee=e.useRef(null),te=e.useRef(null),rt=e.useRef(null),st=e.useRef([]),Pe=e.useRef(null),he=e.useRef(!1),Oe=e.useRef(!1),ne=e.useRef(!1),K=e.useRef(null),ot=e.useRef(null),lt=e.useRef({markerCount:0,currentIndex:-1,canGoNext:!1}),{currentElementList:M,stepElementLists:ut,slideElementList:k,currentIndex:c,audioList:b,currentAudioSequenceIndexes:be,currentStepHasSpeakableElement:h,currentInteractionElement:m,canGoPrev:Nt,canGoNext:S,handlePrev:it,handleNext:R}=Tn.default(o),re=e.useMemo(()=>{if(!(c<0))return k[c]},[c,k]),Lt=k.filter(t=>t.is_renderable!==!1).length===1,g=C&&(k.length>0||b.length>0||!!m),A=e.useMemo(()=>be.map(t=>b[t]?.audioKey).filter(t=>!!t),[b,be]),[at,xe]=e.useState(!0),[ye,se]=e.useState(!1),[oe,ct]=e.useState(!0),[p,D]=e.useState(null),[Vt,Kt]=e.useState(!1),[P,Fe]=e.useState(!1),[v,dt]=e.useState(!1),[Dt,qe]=e.useState(!1),[ft,Ut]=e.useState(!0),[Be,Ne]=e.useState(!1),[u,Le]=e.useState(),[Se,ve]=e.useState(!1),[Ht,le]=e.useState(0),[$t,Wt]=e.useState(!1),I=e.useMemo(()=>_e.isMobileDevice(),[]),[ge,Ve]=e.useState(de.DEFAULT_MOBILE_VIEW_MODE),[mt,Ke]=e.useState(!1),[De,pt]=e.useState(()=>I?_e.isLandscapeViewport():!1),[zt,Ee]=e.useState(!1),U=e.useMemo(()=>On.createPlaybackTimeStore(),[]),{effectiveMobileViewMode:O,isImmersiveMobileFullscreen:H,isNativeMobileFullscreen:ht,shouldRotateFullscreenViewport:Gt}=e.useMemo(()=>de.resolveMobileViewModeState({hasManualMobileViewMode:mt,isMobileDevice:I,mobileViewMode:ge}),[mt,I,De,ge]),bt=e.useRef(O),_=g&&(T||at),Yt=H&&_,Xt=H&&_,Jt=H||ht,Qt=Ge?.fullscreenHintText??ze.DEFAULT_SLIDE_PLAYER_TEXTS.fullscreenHintText,ue=e.useMemo(()=>Hn(o),[o]),a=e.useCallback((t,n,l)=>{Kt(d=>(console.log("[Slide buffering loading]",{reason:n,previousVisible:d,nextVisible:t,currentIndex:c,currentAudioKey:p,currentStepHasSpeakableElement:h,hasCompletedCurrentStepAudio:v,hasStreamInactivityTimedOut:P,isStreaming:s,streamActivityKey:ue,...l}),t))},[p,c,h,v,P,s,ue]),Zt=e.useCallback(t=>{Ke(!0),Ve(t)},[]),xt=e.useCallback(()=>{Ke(!1),Ve(de.DEFAULT_MOBILE_VIEW_MODE)},[]),en=e.useCallback(()=>{xt(),B?.onBack?.()},[B,xt]),tn=e.useCallback(()=>{Ee(!1)},[]),yt=e.useCallback(t=>{Ne(t)},[]),St=e.useCallback(()=>{Ne(t=>!t)},[]),{mountedStepStates:nn,currentMountedStateIndex:rn}=e.useMemo(()=>{const t=[],n=new Map;return ut.forEach((l,d)=>{const i=t.findIndex(f=>Kn(f.elementList,l));if(i>=0){t[i]?.sourceStepIndexes.push(d),n.set(d,i);return}t.push({elementList:l,sourceStepIndexes:[d]}),n.set(d,t.length-1)}),{mountedStepStates:t,currentMountedStateIndex:c>=0?n.get(c)??-1:-1}},[c,ut]),vt=e.useMemo(()=>String(c),[c]),x=e.useMemo(()=>p?b.findIndex(t=>(t.audioKey??"")===p):-1,[b,p]),Ue=e.useMemo(()=>x>=0?b[x]:void 0,[b,x]),sn=Ue?.element?.subtitle_cues??[],Re=e.useMemo(()=>A[0]??"none",[A]),He=e.useMemo(()=>({currentElement:Pt.resolvePlayerCustomActionElement({currentAudioIndex:x,currentAudioSequenceIndexes:be,audioList:b,currentInteractionElement:u,currentStepElement:re}),currentIndex:c,currentStepElement:re,isActive:Be,setActive:yt,toggleActive:St}),[u,b,x,be,c,re,Be,yt,St]),$e=e.useMemo(()=>Pt.getPlayerCustomActionCount(V,He),[He,V]),on=e.useMemo(()=>({"--slide-player-custom-action-count":String($e),"--slide-player-mobile-control-count":String($e+4)}),[$e]),gt=A.length>0,Et=e.useMemo(()=>m?`${m.sequence_number??"none"}:${String(m.content??"")}`:"none",[m]),ie=e.useMemo(()=>[vt,Et].join("|"),[Et,vt]),ln=e.useMemo(()=>[ie,Ue?.audioKey??"none",String(x)].join("|"),[x,Ue?.audioKey,ie]),Rt=!!e.useMemo(()=>!Re||Re==="none"?"":b.find(n=>n.audioKey===Re)?.audioUrl?.trim()??"",[b,Re]),F=X&&!!V&&Be,ae=e.useMemo(()=>Fn.shouldUseAutoAdvanceToggle({canGoNext:S,currentAudioIndex:x,currentStepHasSpeakableElement:h,hasInteraction:!!m}),[S,x,m,h]),N=e.useCallback(()=>{J.current!==null&&(window.clearTimeout(J.current),J.current=null)},[]),j=e.useCallback(()=>{Z.current!==null&&(window.clearTimeout(Z.current),Z.current=null)},[]),w=e.useCallback(()=>{ee.current!==null&&(window.clearTimeout(ee.current),ee.current=null)},[]),$=e.useCallback(()=>{Q.current!==null&&(window.clearTimeout(Q.current),Q.current=null)},[]),W=e.useCallback(()=>{te.current!==null&&(window.clearTimeout(te.current),te.current=null)},[]),z=e.useCallback(()=>{$(),j(),w(),D(null),U.reset(),a(!1,"reset-audio-sequence"),dt(!1),qe(!1),Le(void 0),ve(!1),le(0)},[$,j,w,U,a]),G=e.useCallback(()=>{const t=A[0];return t?(D(t),!0):!1},[A]),Ae=e.useCallback(()=>{j(),w(),ve(!1),le(0),!G()&&S&&R()},[S,j,w,R,G]),At=e.useCallback(t=>{if(w(),!t)return;const n=()=>{ee.current=null,le(Ln),ve(!0),K.current=null};ee.current=window.setTimeout(n,Nn)},[w]),y=e.useCallback((t=ye)=>{g&&(xe(!0),N(),!(T||!t||Te<=0)&&(J.current=window.setTimeout(()=>{xe(!1),J.current=null},Te)))},[N,ye,T,Te,g]),ce=!!(m?.readonly||m?.user_input?.trim()),L=!!m&&!ce;e.useEffect(()=>{ct(!0),X&&Ne(!1)},[c,X]),e.useEffect(()=>()=>{$(),N(),j(),w(),W()},[$,j,w,N,W]),e.useEffect(()=>{if(!s||Me<=0){W(),Pe.current=null,Oe.current=!1,ne.current=!1,Fe(!1);return}const t=!Oe.current,n=Pe.current!==ue;return Oe.current=!0,(t||n)&&(Pe.current=ue,ne.current&&(ne.current=!1,Fe(!1))),W(),te.current=window.setTimeout(()=>{te.current=null,!ne.current&&(ne.current=!0,Fe(!0),a(!1,"stream-inactivity-timeout"),Qe?.({code:ze.SLIDE_ERROR_CODES.STREAM_INACTIVITY_TIMEOUT}))},Me),()=>{W()}},[W,s,Qe,ue,Me,a]),e.useEffect(()=>(ke?.(_),()=>{ke?.(!1)}),[ke,_]),e.useEffect(()=>{I||ge===de.DEFAULT_MOBILE_VIEW_MODE||(Ke(!1),Ve(de.DEFAULT_MOBILE_VIEW_MODE))},[I,ge]),e.useEffect(()=>{if(!I){pt(!1);return}const t=()=>{pt(_e.isLandscapeViewport())};return t(),_e.subscribeMobileDeviceChange(t)},[I]),e.useEffect(()=>{Je?.(O)},[O,Je]),e.useEffect(()=>{const l=bt.current!=="fullscreen"&&O==="fullscreen"&&!De;if(bt.current=O,!I){Ee(!1);return}if(l){Ee(!0);return}O!=="fullscreen"&&Ee(!1)},[O,I,De]),e.useEffect(()=>{Ze?.(re,c)},[c,re,Ze]),e.useEffect(()=>{const t=lt.current,n=jn.shouldAutoAdvanceIntoAppendedMarker({previousMarkerCount:t.markerCount,nextMarkerCount:k.length,previousIndex:t.currentIndex,previousCanGoNext:t.canGoNext,nextCanGoNext:S,currentAudioKey:p,hasCompletedCurrentStepAudio:v,hasResolvedCurrentInteraction:ce,currentStepHasSpeakableElement:h,currentInteractionElement:m,isAutoAdvanceEnabled:oe,shouldUseSilentStepAutoAdvanceToggle:ae});lt.current={markerCount:k.length,currentIndex:c,canGoNext:S},n&&R()},[S,p,c,m,h,R,v,ce,oe,ae,k.length]),e.useEffect(()=>{if(!g){N(),xe(!1);return}if(T){N(),xe(!0);return}ye||y(!0)},[N,ye,T,g,y]),e.useEffect(()=>{if(typeof window>"u")return;const t=n=>{n.origin===window.location.origin&&Rn.isSandboxInteractionMessage(n.data)&&n.data.eventType==="click"&&g&&(se(!0),y(!0))};return window.addEventListener("message",t),()=>{window.removeEventListener("message",t)}},[g,y]),Mn.default({sectionRef:pe,enabled:g,onWake:()=>{se(!0),y(!0)}}),e.useEffect(()=>{const{hasPlaybackContextChanged:t,shouldInitializeAudioSequence:n}=Pn.getPlaybackSequenceTransition({previousResetKey:ot.current,nextResetKey:ie,currentAudioKey:p,hasCompletedCurrentStepAudio:v});ot.current=ie;const l=K.current===c&&!!m,d=kn.shouldPresentInteractionOverlay({hasInteraction:!!m,shouldBlockPlaybackForInteraction:L,shouldOpenInteractionOverlayAfterAudio:l,hasPlaybackContextChanged:t,hasResolvedCurrentInteraction:ce,currentStepHasSpeakableElement:h});if(t&&z(),!(M.length===0&&!m)&&!F){if(m&&Le(m),d){At(m);return}if(w(),K.current=null,!!n&&!G()){if(h){if(P){a(!1,"step-wait-suppressed-after-timeout");return}a(!0,"step-waiting-for-first-audio");return}if(S&&!(ae&&!oe))return Q.current=window.setTimeout(()=>{Q.current=null,R()},Ye),()=>{$()}}}},[S,$,M.length,m,p,ie,h,Ye,R,v,P,oe,ce,L,w,z,At,G,F,ae,a]),e.useEffect(()=>{if(P||F||!h||L){a(!1,"loading-hidden-blocked-state",{shouldPausePlaybackForCustomAction:F,shouldBlockPlaybackForInteraction:L});return}if(v){a(!1,"loading-hidden-step-audio-completed");return}if(gt){a(!1,"loading-hidden-audio-available");return}a(!0,"loading-visible-awaiting-step-audio")},[P,gt,h,v,F,L,a]),e.useEffect(()=>{p||A.length===0||F||!h||L||v||G()},[p,A,h,v,F,L,G]),e.useEffect(()=>{!p||x>=0||D(null)},[x,p]),e.useEffect(()=>{x>=0||U.reset()},[x,U]),e.useEffect(()=>{qe(!1)},[ln]);const It=e.useMemo(()=>{if(!u)return{};const t=!!u.user_input?.trim();return jt.getInteractionDefaultValues(typeof u.content=="string"?u.content:void 0,u.user_input,t?void 0:me)},[u,me]),un=e.useMemo(()=>{if(!u)return;const t=!!u.user_input?.trim();return jt.getInteractionDefaultSelectedValues(typeof u.content=="string"?u.content:void 0,u.user_input,t?void 0:me)},[u,me]),_t=!!u?.user_input?.trim(),wt=!!u?.readonly||_t,Ct=wt||_t,We=!!u&&Se,an=e.useCallback(t=>{const l=[...t.selectedValues??[],t.inputText?.trim()??"",t.buttonText?.trim()??""].filter(Boolean).join(", ");Le(d=>!d||!l?d:{...d,user_input:l}),Xe?.(t,u),Ae()},[u,Ae,Xe]);e.useEffect(()=>{const t=()=>{Wt(document.fullscreenElement===pe.current)};return t(),document.addEventListener("fullscreenchange",t),()=>{document.removeEventListener("fullscreenchange",t)}},[]),e.useEffect(()=>{if(!We){le(0);return}const t=rt.current;if(!t)return;const n=()=>{const d=Math.ceil(t.getBoundingClientRect().height);le(d+Vn)};if(n(),typeof ResizeObserver>"u")return;const l=new ResizeObserver(()=>{n()});return l.observe(t),()=>{l.disconnect()}},[We]),e.useEffect(()=>{if(j(),!(!Se||!Ct))return Z.current=window.setTimeout(()=>{Z.current=null,Ae()},2e3),()=>{j()}},[j,Ae,Se,Ct]);const cn=(t,n={})=>t?t.type==="slot"?r.jsxRuntimeExports.jsx(r.jsxRuntimeExports.Fragment,{children:t.content}):t.type==="html"?r.jsxRuntimeExports.jsx(kt.default,{className:"content-render-iframe",hideFullScreen:!0,mode:"blackboard",replaceRootScreenHeightWithFull:n.replaceRootScreenHeightWithFull,type:"sandbox",content:t.content,enableScaling:Ft}):r.jsxRuntimeExports.jsx(kt.default,{className:"content-render-iframe",hideFullScreen:!0,mode:"blackboard",type:"markdown",content:t.content}):null,dn=(t=[],n=!1)=>{if(t.length===0)return null;const l=t.filter(i=>i.is_renderable!==!1).length,d=t.reduce((i,f,E)=>f.is_renderable!==!1?E:i,-1);return r.jsxRuntimeExports.jsx("div",{className:"slide-stage__content flex w-full flex-col gap-4",children:t.map((i,f)=>{const E=i.type==="html"&&i.is_renderable===!1;return r.jsxRuntimeExports.jsx("div",{ref:n&&f===d?nt:null,"aria-hidden":E||void 0,className:Y.cn("w-full shrink-0",l===1&&i.is_renderable!==!1&&"slide-element--single",E?"pointer-events-none fixed left-[-200vw] top-0 -z-10 h-[100dvh] w-[100vw] overflow-hidden opacity-0":i.is_renderable===!1&&"hidden"),children:cn(i,{replaceRootScreenHeightWithFull:l===1&&i.type==="html"&&i.is_renderable!==!1})},i.sequence_number??`${i.type}-${f}`)})})},fn=e.useCallback(()=>{const t=pe.current;if(t){if(document.fullscreenElement===t){document.exitFullscreen().catch(()=>{});return}t.requestFullscreen?.().catch(()=>{})}},[]),Tt=e.useCallback(()=>{const t=je.current;t&&t.scrollTo({top:t.scrollHeight,behavior:"smooth"})},[]),mn=e.useCallback(()=>{he.current=!0,K.current=null,se(!0),a(!1,"player-prev"),y(!0),z(),it()},[it,z,y,a]),pn=e.useCallback(()=>{he.current=!0,K.current=null,se(!0),a(!1,"player-next"),y(!0),z(),R()},[R,z,y,a]),hn=e.useCallback(t=>{if(P||!h||v){a(!1,"player-loading-change-ignored",{loading:t});return}a(t,t?"player-reported-loading":"player-reported-ready")},[h,v,P,a]),bn=e.useCallback(t=>{const n=b[t]?.audioKey;if(!n||!p||n!==p)return;const l=A.findIndex(f=>f===n);if(l<0){D(null);return}const d=l+1,i=A[d];if(i){D(i);return}if(D(null),dt(!0),a(!1,"player-ended-step-complete"),S){const f=c+1,E=k[f];Rt&&E?.type==="interaction"&&(K.current=f),R()}},[b,S,c,p,A,R,Rt,k,a]),xn=e.useCallback(()=>{u&&ve(t=>!t)},[u]),Mt=e.useCallback(t=>{t.stopPropagation(),_&&y(!0)},[at,y]),yn=e.useCallback(t=>{et?.(t)},[et]),Sn=e.useCallback(()=>{se(!0),y(!0)},[y]),Ie=e.useMemo(()=>M.map((t,n)=>`${t.sequence_number??`${t.type}-${n}`}:${String(t.is_new??"")}`),[M]);return e.useEffect(()=>{const t=st.current,d=(t.length>0&&t.length<Ie.length&&t.every((f,E)=>f===Ie[E])?M.slice(t.length):[]).some(f=>f.is_new===!1);if(st.current=Ie,!d)return;const i=window.requestAnimationFrame(()=>{const f=je.current,E=nt.current;if(!f||!E)return;const vn=f.getBoundingClientRect(),gn=E.getBoundingClientRect(),En=f.scrollTop+(gn.top-vn.top);f.scrollTo({top:Math.max(En,0),behavior:"smooth"})});return()=>{window.cancelAnimationFrame(i)}},[M,Ie]),e.useEffect(()=>{if(!he.current||(he.current=!1,M.length===0))return;const t=window.requestAnimationFrame(()=>{Tt()});return()=>{window.cancelAnimationFrame(t)}},[M,Tt]),r.jsxRuntimeExports.jsxs("section",{ref:pe,className:Y.cn("relative h-full w-full",I&&"slide--mobile-device",H&&"slide--mobile-landscape",ht&&"slide--mobile-landscape-native",qt),onClick:Sn,onPointerDown:yn,...Bt,children:[Jt?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:tt,className:Y.cn("slide__viewport relative h-full min-h-0 w-full",H&&"slide__viewport--mobile-landscape",H&&!Gt&&"slide__viewport--mobile-landscape-native"),children:[Yt?r.jsxRuntimeExports.jsxs("div",{className:"slide-landscape-header",children:[r.jsxRuntimeExports.jsx("button",{"aria-label":B?.backAriaLabel??"Back",className:"slide-landscape-header__back",onClick:en,type:"button",children:r.jsxRuntimeExports.jsx(qn.default,{className:"h-6 w-6 text-white",strokeWidth:2.25})}),B?.content?r.jsxRuntimeExports.jsx("div",{className:"min-w-0 flex-1 overflow-hidden",children:B.content}):null]}):null,r.jsxRuntimeExports.jsx("div",{className:Y.cn("h-full min-h-0 w-full",Xt&&"slide__viewport-content--with-header",Lt?"slide-content--single":"grid gap-4"),children:M.length>0?r.jsxRuntimeExports.jsx("div",{className:"slide-stage",children:r.jsxRuntimeExports.jsx("div",{ref:je,className:"slide-stage__layer w-full",children:nn.map((t,n)=>{const l=n===rn;return r.jsxRuntimeExports.jsx("div",{"aria-hidden":!l||void 0,className:"w-full h-full",style:{display:l?void 0:"none"},children:dn(t.elementList,l)},t.sourceStepIndexes[0]??n)})})}):null}),Vt?r.jsxRuntimeExports.jsx(An.default,{message:we,className:"absolute left-1/2 top-1/2 z-[3] -translate-x-1/2 -translate-y-1/2"}):null,r.jsxRuntimeExports.jsx(Cn.default,{onClose:tn,open:zt,text:Qt}),r.jsxRuntimeExports.jsx(wn.default,{extraBottomOffset:Ht,hasPlayerGap:_,isEnabled:ft&&Dt,isPlayerHidden:g&&!_,playbackTimeStore:U,subtitleCues:sn}),We?r.jsxRuntimeExports.jsx("div",{ref:rt,className:Y.cn("slide-interaction-overlay",_&&g?"slide-interaction-overlay--with-player":"slide-interaction-overlay--standalone"),onClick:Mt,onPointerDown:Mt,style:on,children:r.jsxRuntimeExports.jsx(Ot,{content:String(u?.content??""),defaultButtonText:It.buttonText??"",defaultInputText:It.inputText??"",defaultSelectedValues:un,confirmButtonText:fe?.confirmButtonText,copyButtonText:fe?.copyButtonText,copiedButtonText:fe?.copiedButtonText,onSend:an,readonly:wt,title:fe?.title??Ce??"Submit the content below to continue."})}):null,g?r.jsxRuntimeExports.jsx(_n.default,{audioList:b,className:Y.cn("absolute left-1/2 bottom-6 z-[2] -translate-x-1/2",q,!_&&"pointer-events-none opacity-0"),currentAudioIndex:x,defaultPlaying:!0,isPlaybackPaused:F,isAutoAdvanceEnabled:oe,hasInteraction:!!u,isInteractionOpen:Se,isSubtitleEnabled:ft,onAutoAdvanceToggle:ct,onLoadingChange:hn,onPlaybackStarted:()=>{qe(!0)},onPlaybackTimeChange:U.setTime,onSubtitleToggle:()=>{Ut(t=>!t)},nextDisabled:!S,onEnded:bn,onFullscreen:fn,isFullscreen:$t,mobileViewMode:O,settingsPortalContainer:tt.current,onMobileViewModeChange:Zt,onInteractionToggle:xn,onNext:pn,onPrev:mn,prevDisabled:!Nt,showControls:_,texts:Ge,customActionContext:He,customActions:V,useAutoAdvanceToggle:ae}):null]})]})};exports.default=$n;
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