markdown-flow-ui 0.2.33 → 0.2.35-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,142 +1,143 @@
1
- import { jsx as I, jsxs as Rt } from "react/jsx-runtime";
2
- import q, { useRef as o, useCallback as Xe, useState as _, useEffect as w, useMemo as vt } from "react";
3
- import { createRoot as St } from "react-dom/client";
4
- import Ct from "./SandboxApp.es.js";
5
- import yt from "./ContentRender.es.js";
6
- import { inspectViewportHeightFromHtmlRootString as Ke, EMPTY_ROOT_HEIGHT_META as Et, parseExplicitHeight as Je, inspectViewportHeightFromNodeChain as Mt, resolveExplicitHeightFromNodeChain as Tt } from "./utils/iframe-viewport-height.es.js";
7
- import { SANDBOX_INTERACTION_MESSAGE_TYPE as kt, SANDBOX_INTERACTION_MESSAGE_SOURCE as At } from "../../lib/sandboxInteraction.es.js";
8
- import { injectScalingSystem as Ft } from "./utils/iframe-scaling.es.js";
9
- import { getMarkdownFlowDirection as _t, getMarkdownFlowLanguage as Dt } from "../../lib/locale.es.js";
10
- import { useDetachedLanguage as It } from "../../lib/useDetachedLanguage.es.js";
11
- import { useResolvedDirection as Qe } from "../../lib/useResolvedDirection.es.js";
12
- import { getContentRenderLocaleTexts as Ot } from "./contentRenderI18n.es.js";
13
- import { CJK_SAFE_SANS_FONT_FAMILY as Nt } from "./cjkFontFamily.es.js";
14
- let Ce = null;
15
- const Ze = () => (Ce || (Ce = import("./blackboard-vendor.es.js")), Ce), Vt = /<img\b[^>]*>/i, Wt = 180, Bt = 240, $t = (i) => i.split(/\s+/).filter(Boolean).map((r) => {
1
+ import { jsx as V, jsxs as Et } from "react/jsx-runtime";
2
+ import j, { useRef as o, useCallback as et, useState as A, useEffect as H, useMemo as Tt } from "react";
3
+ import { createRoot as kt } from "react-dom/client";
4
+ import At from "./SandboxApp.es.js";
5
+ import { normalizeContentViewportMinHeight as Ft } from "./utils/content-viewport-min-height.es.js";
6
+ import _t from "./ContentRender.es.js";
7
+ import { inspectViewportHeightFromHtmlRootString as tt, EMPTY_ROOT_HEIGHT_META as Dt, parseExplicitHeight as nt, inspectViewportHeightFromNodeChain as It, resolveExplicitHeightFromNodeChain as Ot } from "./utils/iframe-viewport-height.es.js";
8
+ import { SANDBOX_INTERACTION_MESSAGE_TYPE as Nt, SANDBOX_INTERACTION_MESSAGE_SOURCE as Vt } from "../../lib/sandboxInteraction.es.js";
9
+ import { injectScalingSystem as Bt } from "./utils/iframe-scaling.es.js";
10
+ import { getMarkdownFlowDirection as Wt, getMarkdownFlowLanguage as zt } from "../../lib/locale.es.js";
11
+ import { useDetachedLanguage as $t } from "../../lib/useDetachedLanguage.es.js";
12
+ import { useResolvedDirection as rt } from "../../lib/useResolvedDirection.es.js";
13
+ import { getContentRenderLocaleTexts as qt } from "./contentRenderI18n.es.js";
14
+ import { CJK_SAFE_SANS_FONT_FAMILY as Pt } from "./cjkFontFamily.es.js";
15
+ let ye = null;
16
+ const ot = () => (ye || (ye = import("./blackboard-vendor.es.js")), ye), Lt = /<img\b[^>]*>/i, jt = 180, Gt = 240, Yt = (i) => i.split(/\s+/).filter(Boolean).map((r) => {
16
17
  const l = r.split(":");
17
18
  return l[l.length - 1] !== "h-screen" && l[l.length - 1] !== "min-h-screen" ? r : (l[l.length - 1] = "h-full", l.join(":"));
18
- }).join(" "), zt = (i, r) => !r || !i.trim() ? i : i.replace(
19
+ }).join(" "), Ut = (i, r) => !r || !i.trim() ? i : i.replace(
19
20
  /^(\s*<[a-zA-Z][\w:-]*)(\s[^>]*?)?>/,
20
- (l, h, L = "") => {
21
- const p = L.match(/\bclass\s*=\s*(["'])([^"']*)\1/i);
22
- if (!p)
21
+ (l, f, G = "") => {
22
+ const x = G.match(/\bclass\s*=\s*(["'])([^"']*)\1/i);
23
+ if (!x)
23
24
  return l;
24
- const O = $t(p[2]);
25
- return O === p[2] ? l : `${h}${L.replace(
26
- p[0],
27
- `class=${p[1]}${O}${p[1]}`
25
+ const B = Yt(x[2]);
26
+ return B === x[2] ? l : `${f}${G.replace(
27
+ x[0],
28
+ `class=${x[1]}${B}${x[1]}`
28
29
  )}>`;
29
30
  }
30
- ), Pt = ({
31
+ ), Xt = ({
31
32
  content: i,
32
33
  type: r,
33
34
  className: l,
34
- locale: h,
35
- lang: L,
36
- dir: p,
37
- loadingText: O,
38
- styleLoadingText: ye,
35
+ locale: f,
36
+ lang: G,
37
+ dir: x,
38
+ loadingText: B,
39
+ styleLoadingText: Me,
39
40
  scriptLoadingText: Ee,
40
- fullScreenButtonText: et,
41
- exitFullScreenButtonText: tt,
42
- hideFullScreen: nt = !1,
41
+ fullScreenButtonText: it,
42
+ exitFullScreenButtonText: ct,
43
+ hideFullScreen: Te = !1,
43
44
  mode: a = "content",
44
- replaceRootScreenHeightWithFull: rt = !1,
45
- enableScaling: ot = !1,
46
- disableLoadingOverlay: ne = !1
45
+ replaceRootScreenHeightWithFull: st = !1,
46
+ enableScaling: lt = !1,
47
+ disableLoadingOverlay: oe = !1
47
48
  }) => {
48
- const Me = Ot(h), H = p ?? _t(h), re = L ?? Dt(h), it = et || Me.sandboxFullscreenButtonText, ct = tt || Me.sandboxExitFullscreenButtonText, E = o(null), Te = It(E, re), { resolvedDirection: oe } = Qe(E, H), ke = o(null), Ae = o(null), st = Xe(
49
+ const ke = qt(f), R = x ?? Wt(f), ie = G ?? zt(f), at = it || ke.sandboxFullscreenButtonText, ut = ct || ke.sandboxExitFullscreenButtonText, F = o(null), Ae = o(null), Fe = $t(F, ie), { resolvedDirection: ce } = rt(F, R), _e = o(null), De = o(null), dt = et(
49
50
  (t) => {
50
- ke.current = t, Ae.current = t?.querySelector(".content-render") ?? null;
51
+ _e.current = t, De.current = t?.querySelector(".content-render") ?? null;
51
52
  },
52
53
  []
53
- ), { resolvedDirection: lt } = Qe(
54
- Ae,
55
- H
56
- ), Fe = H ?? oe, _e = o(H);
57
- _e.current = H;
58
- const [at, ut] = _();
59
- let j;
60
- H === "auto" && (j = oe, r === "sandbox" ? j = at ?? oe : a === "blackboard" && (j = lt));
61
- const x = o(null), G = o(null), N = o(() => {
62
- }), [dt, ht] = _(480), [De, ft] = _(0), [ie, ce] = _(0), se = o(!1), le = o(!1), Ie = o(0), [Oe, mt] = _(0), [ae, gt] = _(!1), ue = r === "sandbox", R = a === "blackboard", v = ot && R && r === "sandbox", V = R && r === "sandbox", D = V && rt, de = o(""), Y = q.useMemo(
54
+ ), { resolvedDirection: ht } = rt(
55
+ De,
56
+ R
57
+ ), Ie = R ?? ce, Oe = o(R);
58
+ Oe.current = R;
59
+ const [ft, mt] = A();
60
+ let Y;
61
+ R === "auto" && (Y = ce, r === "sandbox" ? Y = ft ?? ce : a === "blackboard" && (Y = ht));
62
+ const C = o(null), U = o(null), W = o(() => {
63
+ }), [gt, bt] = A(480), [se, wt] = A(null), [X, le] = A(0), [Ne, pt] = A(0), ae = o(!1), ue = o(!1), Ve = o(0), [Be, Ht] = A(0), [de, xt] = A(!1), he = r === "sandbox", v = a === "blackboard", S = lt && v && r === "sandbox", z = v && r === "sandbox", O = z && st, fe = o(""), K = j.useMemo(
63
64
  () => r === "sandbox" ? i : "",
64
65
  [i, r]
65
- ), c = q.useMemo(
66
- () => zt(
67
- Y,
68
- D
66
+ ), c = j.useMemo(
67
+ () => Ut(
68
+ K,
69
+ O
69
70
  ),
70
- [Y, D]
71
- ), Ne = q.useMemo(
72
- () => D ? Ke(Y) : Et,
73
- [Y, D]
74
- ), he = q.useMemo(
75
- () => D && Ne.hasFullViewportHeight,
71
+ [K, O]
72
+ ), We = j.useMemo(
73
+ () => O ? tt(K) : Dt,
74
+ [K, O]
75
+ ), me = j.useMemo(
76
+ () => O && We.hasFullViewportHeight,
76
77
  [
77
- Ne.hasFullViewportHeight,
78
- D
78
+ We.hasFullViewportHeight,
79
+ O
79
80
  ]
80
- ), [U, Ve] = _(
81
+ ), [J, ze] = A(
81
82
  c
82
- ), We = o(c), fe = o(c), W = o(null), S = o(null), Be = o(null), me = Xe((t) => {
83
+ ), $e = o(c), ge = o(c), $ = o(null), y = o(null), qe = o(null), be = et((t) => {
83
84
  if (typeof window > "u")
84
85
  return;
85
86
  const e = Date.now();
86
- e - Ie.current < Bt || (Ie.current = e, window.postMessage(
87
+ e - Ve.current < Gt || (Ve.current = e, window.postMessage(
87
88
  {
88
- source: At,
89
- type: kt,
89
+ source: Vt,
90
+ type: Nt,
90
91
  eventType: t
91
92
  },
92
93
  window.location.origin
93
94
  ));
94
95
  }, []);
95
- w(() => {
96
+ H(() => {
96
97
  if (r !== "markdown" || a !== "blackboard") return;
97
- const t = ke.current;
98
+ const t = _e.current;
98
99
  if (!t) return;
99
- const e = () => me("click");
100
+ const e = () => be("click");
100
101
  return t.addEventListener("click", e), () => t.removeEventListener("click", e);
101
- }, [me, a, r]);
102
- const ge = () => {
103
- W.current !== null && (window.clearTimeout(W.current), W.current = null);
104
- }, bt = () => {
105
- S.current !== null && (window.cancelAnimationFrame(S.current), S.current = null);
102
+ }, [be, a, r]);
103
+ const we = () => {
104
+ $.current !== null && (window.clearTimeout($.current), $.current = null);
105
+ }, Rt = () => {
106
+ y.current !== null && (window.cancelAnimationFrame(y.current), y.current = null);
106
107
  };
107
- w(
108
+ H(
108
109
  () => () => {
109
- ge(), bt();
110
+ we(), Rt();
110
111
  },
111
112
  []
112
- ), w(() => {
113
- const t = We.current;
114
- We.current = c;
115
- const e = !!t && c.length > t.length && c.startsWith(t), f = Vt.test(
113
+ ), H(() => {
114
+ const t = $e.current;
115
+ $e.current = c;
116
+ const e = !!t && c.length > t.length && c.startsWith(t), u = Lt.test(
116
117
  c
117
118
  );
118
- if (!(e && f)) {
119
- ge(), fe.current = c, Ve(c);
119
+ if (!(e && u)) {
120
+ we(), ge.current = c, ze(c);
120
121
  return;
121
122
  }
122
- fe.current = c, ge(), W.current = window.setTimeout(() => {
123
- Ve(fe.current), W.current = null;
124
- }, Wt);
123
+ ge.current = c, we(), $.current = window.setTimeout(() => {
124
+ ze(ge.current), $.current = null;
125
+ }, jt);
125
126
  }, [c]);
126
- const X = q.useMemo(() => V ? Ke(U).viewportHeightCss : null, [U, V]);
127
- w(() => {
128
- Be.current = X;
129
- }, [X]);
130
- const be = !!X, B = R && r === "sandbox" ? v || he ? "100%" : X ?? `${dt}px` : void 0;
131
- w(() => {
127
+ const Q = j.useMemo(() => z ? tt(J).viewportHeightCss : null, [J, z]);
128
+ H(() => {
129
+ qe.current = Q;
130
+ }, [Q]);
131
+ const pe = !!Q, q = v && r === "sandbox" ? S || me ? "100%" : Q ?? `${gt}px` : void 0;
132
+ H(() => {
132
133
  if (a !== "blackboard") {
133
- de.current = c;
134
+ fe.current = c;
134
135
  return;
135
136
  }
136
- const t = de.current;
137
- !(t && c.startsWith(t)) && t && mt((f) => f + 1), de.current = c;
138
- }, [a, c]), w(() => {
139
- const t = x.current;
137
+ const t = fe.current;
138
+ !(t && c.startsWith(t)) && t && Ht((u) => u + 1), fe.current = c;
139
+ }, [a, c]), H(() => {
140
+ const t = C.current;
140
141
  if (!t) return;
141
142
  const e = t.contentDocument;
142
143
  if (!e) return;
@@ -147,9 +148,9 @@ const Ze = () => (Ce || (Ce = import("./blackboard-vendor.es.js")), Ce), Vt = /<
147
148
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
148
149
  <style>
149
150
  :root { color-scheme: light; }
150
- html, body, #root { width: 100%; font-family: ${Nt}; }
151
+ html, body, #root { width: 100%; font-family: ${Pt}; }
151
152
  ${a === "blackboard" ? "html, body, #root { height: 100%; }" : ""}
152
- html, body { margin: 0; padding: 0; overflow: ${v ? "hidden auto" : a === "blackboard" ? "auto" : "hidden"}; }
153
+ html, body { margin: 0; padding: 0; overflow: ${S ? "hidden auto" : a === "blackboard" ? "auto" : "hidden"}; }
153
154
  *, *::before, *::after { box-sizing: border-box; }
154
155
  ${a !== "blackboard" ? `
155
156
  .h-screen { height: auto !important; }
@@ -163,208 +164,226 @@ const Ze = () => (Ce || (Ce = import("./blackboard-vendor.es.js")), Ce), Vt = /<
163
164
  <div id="root"></div>
164
165
  </body>
165
166
  </html>`), e.close(), e.documentElement.setAttribute("data-theme", "light"), e.documentElement.style.colorScheme = "light", e.body?.style.setProperty("color-scheme", "light");
166
- const f = R && r === "sandbox", K = () => me("click");
167
- f && e.addEventListener("click", K, !0);
168
- const $ = e.getElementById("root");
169
- if (!$) return;
170
- const we = St($);
171
- G.current = we;
172
- let C = !1;
173
- const ze = (n) => ({
167
+ const u = v && r === "sandbox", M = () => be("click");
168
+ u && e.addEventListener("click", M, !0);
169
+ const _ = e.getElementById("root");
170
+ if (!_) return;
171
+ const N = kt(_);
172
+ U.current = N;
173
+ let m = !1;
174
+ const Pe = (n) => ({
174
175
  heightAttrValue: n.getAttribute("height"),
175
176
  styleAttrValue: n.getAttribute("style"),
176
177
  classAttrValue: n.getAttribute("class")
177
- }), Pe = (n) => {
178
+ }), Le = (n) => {
178
179
  const s = Array.from(n.children);
179
180
  return s.length === 1 ? s[0] : null;
180
- }, Ht = () => {
181
- if (!V || !x.current || !e.body) return null;
182
- const n = x.current.ownerDocument?.documentElement?.clientHeight || window.innerHeight, s = Be.current, g = s ? Je(
181
+ }, yt = () => {
182
+ if (!z || !C.current || !e.body) return null;
183
+ const n = C.current.ownerDocument?.documentElement?.clientHeight || window.innerHeight, s = qe.current, b = s ? nt(
183
184
  s,
184
185
  n
185
186
  ) : null;
186
- if (g !== null)
187
- return Math.ceil(g);
188
- const m = e.body.querySelector(
187
+ if (b !== null)
188
+ return Math.ceil(b);
189
+ const E = e.body.querySelector(
189
190
  ".sandbox-wrapper"
190
191
  )?.firstElementChild;
191
- if (!m) return null;
192
- const b = Array.from(m.children), k = b.length === 1 ? b[0] : null, ee = Mt(
193
- k,
192
+ if (!E) return null;
193
+ const g = Array.from(E.children), w = g.length === 1 ? g[0] : null, P = It(
194
+ w,
194
195
  {
195
- getNode: ze,
196
- getSingleChild: Pe
196
+ getNode: Pe,
197
+ getSingleChild: Le
197
198
  }
198
199
  ).viewportHeightCss;
199
- if (ee) {
200
- const z = Je(
201
- ee,
200
+ if (P) {
201
+ const h = nt(
202
+ P,
202
203
  n
203
204
  );
204
- if (z !== null)
205
- return Math.ceil(z);
205
+ if (h !== null)
206
+ return Math.ceil(h);
206
207
  }
207
- const d = Tt(
208
- k,
208
+ const ne = Ot(
209
+ w,
209
210
  n,
210
211
  {
211
- getNode: ze,
212
- getSingleChild: Pe
212
+ getNode: Pe,
213
+ getSingleChild: Le
213
214
  }
214
215
  );
215
- return d !== null ? Math.ceil(d) : null;
216
- }, pe = () => {
217
- if (!x.current || !e.body) return;
218
- if (!R) {
219
- if (se.current) {
220
- le.current = !0;
216
+ return ne !== null ? Math.ceil(ne) : null;
217
+ }, xe = () => {
218
+ if (!C.current || !e.body) return;
219
+ if (!v) {
220
+ if (ae.current) {
221
+ ue.current = !0;
221
222
  return;
222
223
  }
223
- se.current = !0;
224
- const m = x.current, b = E.current?.clientWidth || 0, k = m.style.height;
225
- if (b > 0) {
226
- const Se = Math.round(b * 9 / 16), ee = Math.max(8192, b * 20);
227
- m.style.height = Se + "px", e.body.offsetHeight;
228
- let d = e.body.scrollHeight;
229
- const z = e.defaultView;
230
- if (z) {
231
- const P = (y) => {
232
- let A = 0;
233
- const Ye = (F) => {
234
- if (F !== y && F.scrollHeight > F.clientHeight + 1) {
235
- const te = z.getComputedStyle(F).overflowY;
236
- if (te === "auto" || te === "scroll") {
237
- const Ue = F.getBoundingClientRect();
238
- Ue.top >= 0 && (A = Math.max(
239
- A,
240
- Math.ceil(Ue.top + F.scrollHeight)
224
+ ae.current = !0;
225
+ const E = e.body.querySelector(".sandbox-container");
226
+ E && Ft(E);
227
+ const g = C.current, w = F.current?.clientWidth || 0, Xe = g.style.height;
228
+ if (w > 0) {
229
+ const P = Math.round(w * 9 / 16), ne = Math.max(8192, w * 20);
230
+ g.style.height = P + "px", e.body.offsetHeight;
231
+ let h = e.body.scrollHeight;
232
+ const Ke = e.defaultView;
233
+ if (Ke) {
234
+ const L = (T) => {
235
+ let p = 0;
236
+ const Je = (k) => {
237
+ const Qe = Ke.getComputedStyle(k);
238
+ if (Qe.position === "fixed" && (p = Math.max(
239
+ p,
240
+ Math.ceil(k.getBoundingClientRect().bottom)
241
+ )), k !== T && k.scrollHeight > k.clientHeight + 1) {
242
+ const re = Qe.overflowY;
243
+ if (re === "auto" || re === "scroll") {
244
+ const Ze = k.getBoundingClientRect();
245
+ Ze.top >= 0 && (p = Math.max(
246
+ p,
247
+ Math.ceil(Ze.top + k.scrollHeight)
241
248
  ));
242
249
  }
243
250
  }
244
- for (const te of F.children) Ye(te);
251
+ for (const re of k.children) Je(re);
245
252
  };
246
- return Ye(y), A;
253
+ return Je(T), p;
247
254
  };
248
- d = Math.max(d, P(e.body));
249
- for (let y = 0; y < 8 && d > Se; y++) {
250
- m.style.height = d + "px", e.body.offsetHeight;
251
- const A = Math.max(
255
+ h = Math.max(h, L(e.body));
256
+ for (let T = 0; T < 8 && h > P; T++) {
257
+ g.style.height = h + "px", e.body.offsetHeight;
258
+ const p = Math.max(
252
259
  e.body.scrollHeight,
253
- P(e.body)
260
+ L(e.body)
254
261
  );
255
- if (A <= d + 1 || A >= d * 1.5) break;
256
- d = A;
262
+ if (p <= h + 1 || p >= h * 1.5) break;
263
+ h = p;
257
264
  }
258
265
  }
259
- m.style.height = k, ft((P) => {
260
- const y = Math.min(ee, Math.max(200, Math.ceil(d)));
261
- return P === y ? P : y;
266
+ g.style.height = Xe, wt((L) => {
267
+ const T = Math.min(ne, Math.max(1, Math.ceil(h)));
268
+ return L === T ? L : T;
262
269
  });
263
270
  }
264
271
  setTimeout(() => {
265
- se.current = !1, le.current && (le.current = !1, M());
272
+ ae.current = !1, ue.current && (ue.current = !1, D());
266
273
  }, 50);
267
274
  return;
268
275
  }
269
- if (v) return;
270
- const n = e.body.scrollHeight, s = e.documentElement?.scrollHeight || 0, g = $?.scrollHeight || 0, T = Math.max(n, s, g);
271
- if (V) {
272
- const m = Ht(), b = Math.max(
276
+ if (S) return;
277
+ const n = e.body.scrollHeight, s = e.documentElement?.scrollHeight || 0, b = _?.scrollHeight || 0, I = Math.max(n, s, b);
278
+ if (z) {
279
+ const E = yt(), g = Math.max(
273
280
  200,
274
- m ?? Math.ceil(T)
281
+ E ?? Math.ceil(I)
275
282
  );
276
- ht(
277
- (k) => k === b ? k : b
283
+ bt(
284
+ (w) => w === g ? w : g
278
285
  );
279
286
  }
280
- }, M = () => {
287
+ }, D = () => {
281
288
  requestAnimationFrame(() => {
282
- C || pe();
289
+ m || xe();
283
290
  });
284
291
  };
285
- N.current = M, pe(), M(), ue && Ze().then(({ injectBlackboardLibraries: n }) => {
286
- C || (n(e), v && Ft(e), requestAnimationFrame(() => {
287
- C || M();
292
+ W.current = D, xe(), D(), he && ot().then(({ injectBlackboardLibraries: n }) => {
293
+ m || (n(e), S && Bt(e), requestAnimationFrame(() => {
294
+ m || D();
288
295
  }));
289
296
  }).catch(() => {
290
- C || M();
297
+ m || D();
291
298
  });
292
- const u = E.current;
293
- let He = !!(u && (u.clientWidth <= 0 || u.clientHeight <= 0)), J = !1, Q = null, Z = null;
294
- const qe = () => {
295
- if (C) return;
296
- M(), t.contentWindow?.__mdf_triggerFitContent?.();
297
- }, xe = () => !!(u && u.clientWidth > 0 && u.clientHeight > 0), Le = () => {
298
- !ue || !u || !He || J || !xe() || (J = !0, Ze().then(({ refreshTailwindRuntime: n }) => {
299
- C || (Q = window.requestAnimationFrame(() => {
300
- Q = null, J = !1;
299
+ const d = F.current;
300
+ let Re = !!(d && (d.clientWidth <= 0 || d.clientHeight <= 0)), Z = !1, ee = null, te = null;
301
+ const je = () => {
302
+ if (m) return;
303
+ D(), t.contentWindow?.__mdf_triggerFitContent?.();
304
+ }, Ce = () => !!(d && d.clientWidth > 0 && d.clientHeight > 0), Ge = () => {
305
+ !he || !d || !Re || Z || !Ce() || (Z = !0, ot().then(({ refreshTailwindRuntime: n }) => {
306
+ m || (ee = window.requestAnimationFrame(() => {
307
+ ee = null, Z = !1;
301
308
  const s = e.querySelector(".sandbox-container");
302
- C || !xe() || !s?.childNodes.length || !n(e) || (He = !1, qe(), Z = window.setTimeout(() => {
303
- Z = null, qe();
309
+ m || !Ce() || !s?.childNodes.length || !n(e) || (Re = !1, je(), te = window.setTimeout(() => {
310
+ te = null, je();
304
311
  }, 100));
305
312
  }));
306
313
  }).catch(() => {
307
- J = !1;
314
+ Z = !1;
308
315
  }));
309
- }, je = typeof ResizeObserver < "u", Re = ue && u && je ? new ResizeObserver((n) => {
310
- const s = n[0]?.contentRect, g = s?.width ?? u.clientWidth, T = s?.height ?? u.clientHeight;
311
- g > 0 && T > 0 && Le();
316
+ }, Ye = typeof ResizeObserver < "u", ve = he && d && Ye ? new ResizeObserver((n) => {
317
+ const s = n[0]?.contentRect, b = s?.width ?? d.clientWidth, I = s?.height ?? d.clientHeight;
318
+ b > 0 && I > 0 && Ge();
312
319
  }) : null;
313
- Re && u && Re.observe(u);
314
- const ve = je ? new ResizeObserver(() => pe()) : null;
315
- ve?.observe(e.body), $ && ve?.observe($);
316
- const xt = () => {
317
- if (r !== "sandbox" || _e.current !== "auto")
320
+ ve && d && ve.observe(d);
321
+ const Se = Ye ? new ResizeObserver(() => xe()) : null;
322
+ Se?.observe(e.body), _ && Se?.observe(_);
323
+ const Mt = () => {
324
+ if (r !== "sandbox" || Oe.current !== "auto")
318
325
  return;
319
326
  const n = e.querySelector(".sandbox-wrapper"), s = e.defaultView;
320
327
  if (!n || !s) return;
321
- const g = s.getComputedStyle(n).direction === "rtl" ? "rtl" : "ltr";
322
- ut(
323
- (T) => T === g ? T : g
328
+ const b = s.getComputedStyle(n).direction === "rtl" ? "rtl" : "ltr";
329
+ mt(
330
+ (I) => I === b ? I : b
324
331
  );
325
- }, Ge = new MutationObserver(() => {
326
- if (xt(), M(), !xe()) {
327
- He = !0;
332
+ }, Ue = new MutationObserver(() => {
333
+ if (Mt(), D(), !Ce()) {
334
+ Re = !0;
328
335
  return;
329
336
  }
330
- Le();
337
+ Ge();
331
338
  });
332
- return Ge.observe(e.body, {
339
+ return Ue.observe(e.body, {
333
340
  childList: !0,
334
341
  characterData: !0,
335
342
  subtree: !0,
336
343
  attributes: !0,
337
344
  attributeFilter: ["style", "class", "dir"]
338
345
  }), () => {
339
- C = !0, Re?.disconnect(), ve?.disconnect(), Ge.disconnect(), Q !== null && window.cancelAnimationFrame(Q), Z !== null && window.clearTimeout(Z), v && t.contentWindow?.__mdf_cleanupScaling?.(), f && e.removeEventListener("click", K, !0), G.current === we && (G.current = null, N.current = () => {
346
+ m = !0, ve?.disconnect(), Se?.disconnect(), Ue.disconnect(), ee !== null && window.cancelAnimationFrame(ee), te !== null && window.clearTimeout(te), S && t.contentWindow?.__mdf_cleanupScaling?.(), u && e.removeEventListener("click", M, !0), U.current === N && (U.current = null, W.current = () => {
340
347
  }), setTimeout(() => {
341
- we.unmount();
348
+ N.unmount();
342
349
  }, 0);
343
350
  };
344
- }, []), w(() => {
351
+ }, []), H(() => {
345
352
  const t = () => {
346
- gt(!!document.fullscreenElement);
353
+ xt(!!document.fullscreenElement);
347
354
  };
348
355
  return document.addEventListener("fullscreenchange", t), () => document.removeEventListener("fullscreenchange", t);
349
- }, []), w(() => {
350
- const t = E.current;
356
+ }, []), H(() => {
357
+ const t = F.current;
351
358
  if (!t) return;
359
+ const e = Ae.current, u = () => {
360
+ pt(
361
+ e ? Math.ceil(e.offsetTop + e.offsetHeight) : 0
362
+ );
363
+ };
352
364
  if (typeof ResizeObserver > "u") {
353
- ce(t.clientWidth);
365
+ le(t.clientWidth), u();
354
366
  return;
355
367
  }
356
- const e = new ResizeObserver((f) => {
357
- ce(f[0]?.contentRect.width ?? t.clientWidth);
368
+ const M = new ResizeObserver((_) => {
369
+ const N = _.find((m) => m.target === t);
370
+ N && le(N.contentRect.width), u();
358
371
  });
359
- return e.observe(t), ce(t.clientWidth), () => e.disconnect();
360
- }, []);
361
- const $e = vt(() => {
362
- if (R || ie === 0 || ae)
372
+ return M.observe(t), e && M.observe(e), le(t.clientWidth), u(), () => M.disconnect();
373
+ }, [Te]);
374
+ const He = Tt(() => {
375
+ if (v || X === 0 || de)
363
376
  return;
364
- const t = Math.round(ie * 9 / 16);
365
- return { height: Math.max(t, De) };
366
- }, [R, ie, De, ae]), wt = () => {
367
- const t = E.current || x.current;
377
+ const t = Math.round(X * 9 / 16);
378
+ return { height: Math.max(se ?? t, Ne) };
379
+ }, [
380
+ v,
381
+ X,
382
+ se,
383
+ de,
384
+ Ne
385
+ ]), Ct = He ? Math.max(Math.round(X * 9 / 16), se ?? 0) : void 0, vt = () => {
386
+ const t = F.current || C.current;
368
387
  if (t) {
369
388
  if (document.fullscreenElement) {
370
389
  document.exitFullscreen().catch(() => {
@@ -375,97 +394,98 @@ const Ze = () => (Ce || (Ce = import("./blackboard-vendor.es.js")), Ce), Vt = /<
375
394
  });
376
395
  }
377
396
  };
378
- w(() => {
379
- const t = G.current;
397
+ H(() => {
398
+ const t = U.current;
380
399
  if (!t) return;
381
400
  t.render(
382
- /* @__PURE__ */ I(
383
- Ct,
401
+ /* @__PURE__ */ V(
402
+ At,
384
403
  {
385
- html: U,
386
- locale: h,
387
- dir: Fe,
388
- lang: Te,
389
- loadingText: O,
390
- styleLoadingText: ye,
404
+ html: J,
405
+ locale: f,
406
+ dir: Ie,
407
+ lang: Fe,
408
+ loadingText: B,
409
+ styleLoadingText: Me,
391
410
  scriptLoadingText: Ee,
392
- disableLoadingOverlay: ne,
393
- resetToken: Oe,
394
- hasRootVhHeight: be,
411
+ disableLoadingOverlay: oe,
412
+ resetToken: Be,
413
+ hasRootVhHeight: pe,
395
414
  mode: a,
396
- stretchRootHeight: he,
397
- enableScaling: v
415
+ stretchRootHeight: me,
416
+ enableScaling: S
398
417
  }
399
418
  )
400
- ), S.current = window.requestAnimationFrame(() => {
401
- N.current?.(), v && x.current?.contentWindow?.__mdf_triggerFitContent?.(), S.current = null;
419
+ ), y.current = window.requestAnimationFrame(() => {
420
+ W.current?.(), S && C.current?.contentWindow?.__mdf_triggerFitContent?.(), y.current = null;
402
421
  });
403
- const e = setTimeout(() => N.current?.(), 100), f = setTimeout(() => N.current?.(), 500);
422
+ const e = setTimeout(() => W.current?.(), 100), u = setTimeout(() => W.current?.(), 500);
404
423
  return () => {
405
- S.current !== null && (window.cancelAnimationFrame(S.current), S.current = null), clearTimeout(e), clearTimeout(f);
424
+ y.current !== null && (window.cancelAnimationFrame(y.current), y.current = null), clearTimeout(e), clearTimeout(u);
406
425
  };
407
426
  }, [
408
- U,
409
- h,
427
+ J,
428
+ f,
429
+ Ie,
410
430
  Fe,
411
- Te,
412
- O,
413
- ye,
431
+ B,
432
+ Me,
414
433
  Ee,
415
- Oe,
416
- ne,
417
- be,
434
+ Be,
435
+ oe,
436
+ pe,
418
437
  a,
419
- he,
420
- v
438
+ me,
439
+ S
421
440
  ]);
422
- const pt = [
441
+ const St = [
423
442
  `w-full relative content-render-iframe-sandbox content-render-iframe-sandbox--${r}`,
424
- R ? "h-full overflow-auto flex flex-col" : $e ? "overflow-hidden flex items-center justify-center" : "aspect-[16/9] overflow-hidden flex items-center justify-center"
443
+ v ? "h-full overflow-auto flex flex-col" : He ? "overflow-hidden" : "aspect-[16/9] overflow-hidden flex items-center justify-center"
425
444
  ].filter(Boolean).join(" ");
426
- return /* @__PURE__ */ Rt(
445
+ return /* @__PURE__ */ Et(
427
446
  "div",
428
447
  {
429
- ref: E,
430
- dir: H,
431
- lang: re,
432
- "data-root-vh": be ? "true" : "false",
433
- className: pt,
434
- style: B ? {
435
- height: B,
436
- minHeight: B
437
- } : $e,
448
+ ref: F,
449
+ dir: R,
450
+ lang: ie,
451
+ "data-root-vh": pe ? "true" : "false",
452
+ className: St,
453
+ style: q ? {
454
+ height: q,
455
+ minHeight: q
456
+ } : He,
438
457
  children: [
439
- !nt && /* @__PURE__ */ I(
458
+ !Te && /* @__PURE__ */ V(
440
459
  "button",
441
460
  {
461
+ ref: Ae,
442
462
  type: "button",
443
- dir: j,
444
- onClick: wt,
463
+ dir: Y,
464
+ onClick: vt,
445
465
  className: "absolute top-2 end-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer",
446
- children: ae ? ct : it
466
+ children: de ? ut : at
447
467
  }
448
468
  ),
449
- a === "blackboard" && r === "markdown" ? /* @__PURE__ */ I("div", { ref: st, children: /* @__PURE__ */ I(
450
- yt,
469
+ a === "blackboard" && r === "markdown" ? /* @__PURE__ */ V("div", { ref: dt, children: /* @__PURE__ */ V(
470
+ _t,
451
471
  {
452
472
  content: i,
453
- locale: h,
454
- dir: H,
455
- lang: re,
456
- disableSandboxLoadingOverlay: ne
473
+ locale: f,
474
+ dir: R,
475
+ lang: ie,
476
+ disableSandboxLoadingOverlay: oe
457
477
  }
458
- ) }) : /* @__PURE__ */ I(
478
+ ) }) : /* @__PURE__ */ V(
459
479
  "iframe",
460
480
  {
461
- ref: x,
481
+ ref: C,
462
482
  sandbox: "allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox",
463
483
  allow: "fullscreen",
464
484
  allowFullScreen: !0,
465
485
  className: [l, "w-full h-full mx-auto my-auto block"].filter(Boolean).join(" "),
466
486
  style: {
467
- height: B ?? "100%",
468
- minHeight: B,
487
+ height: q ?? Ct ?? "100%",
488
+ minHeight: q,
469
489
  margin: "auto"
470
490
  }
471
491
  }
@@ -473,11 +493,11 @@ const Ze = () => (Ce || (Ce = import("./blackboard-vendor.es.js")), Ce), Vt = /<
473
493
  ]
474
494
  }
475
495
  );
476
- }, nn = (i) => {
477
- const r = i.mode ?? "content", l = !!(i.enableScaling && r === "blackboard" && i.type === "sandbox"), h = `${i.type}:${r}:${l ? "scaled" : "unscaled"}`;
478
- return /* @__PURE__ */ I(Pt, { ...i }, h);
496
+ }, dn = (i) => {
497
+ const r = i.mode ?? "content", l = !!(i.enableScaling && r === "blackboard" && i.type === "sandbox"), f = `${i.type}:${r}:${l ? "scaled" : "unscaled"}`;
498
+ return /* @__PURE__ */ V(Xt, { ...i }, f);
479
499
  };
480
500
  export {
481
- nn as default
501
+ dn as default
482
502
  };
483
503
  //# sourceMappingURL=IframeSandbox.es.js.map