markdown-flow-ui 0.1.100-beta.2 → 0.1.100-beta.21

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 (90) hide show
  1. package/dist/Documents/ai-shifu/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
  2. package/dist/Documents/ai-shifu/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
  3. package/dist/Documents/ai-shifu/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
  4. package/dist/Documents/ai-shifu/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
  5. package/dist/Documents/ai-shifu/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
  6. package/dist/Documents/ai-shifu/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
  7. package/dist/Documents/ai-shifu/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
  8. package/dist/Documents/ai-shifu/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
  9. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.cjs.js +1 -1
  10. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-custom-variable.es.js +1 -1
  11. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.cjs.js +1 -1
  12. package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/remark-interaction.es.js +1 -1
  13. package/dist/_virtual/index.cjs3.js +1 -1
  14. package/dist/_virtual/index.cjs4.js +1 -1
  15. package/dist/_virtual/index.es3.js +4 -5
  16. package/dist/_virtual/index.es3.js.map +1 -1
  17. package/dist/_virtual/index.es4.js +5 -4
  18. package/dist/_virtual/index.es4.js.map +1 -1
  19. package/dist/assets/markdown-flow-ui.css +1 -1
  20. package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
  21. package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
  22. package/dist/components/ContentRender/ContentRender.d.ts +13 -10
  23. package/dist/components/ContentRender/ContentRender.es.js +175 -158
  24. package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
  25. package/dist/components/ContentRender/IframeSandbox.cjs.js +3 -3
  26. package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
  27. package/dist/components/ContentRender/IframeSandbox.d.ts +1 -0
  28. package/dist/components/ContentRender/IframeSandbox.es.js +331 -202
  29. package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
  30. package/dist/components/ContentRender/SandboxApp.cjs.js +3 -3
  31. package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
  32. package/dist/components/ContentRender/SandboxApp.d.ts +4 -0
  33. package/dist/components/ContentRender/SandboxApp.es.js +144 -111
  34. package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
  35. package/dist/components/ContentRender/plugins/CustomVariable.cjs.js +1 -1
  36. package/dist/components/ContentRender/plugins/CustomVariable.cjs.js.map +1 -1
  37. package/dist/components/ContentRender/plugins/CustomVariable.es.js +68 -64
  38. package/dist/components/ContentRender/plugins/CustomVariable.es.js.map +1 -1
  39. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js +1 -1
  40. package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js.map +1 -1
  41. package/dist/components/MarkdownFlow/MarkdownFlow.d.ts +3 -0
  42. package/dist/components/MarkdownFlow/MarkdownFlow.es.js +19 -16
  43. package/dist/components/MarkdownFlow/MarkdownFlow.es.js.map +1 -1
  44. package/dist/components/Slide/Player.cjs.js +1 -1
  45. package/dist/components/Slide/Player.cjs.js.map +1 -1
  46. package/dist/components/Slide/Player.d.ts +1 -0
  47. package/dist/components/Slide/Player.es.js +208 -168
  48. package/dist/components/Slide/Player.es.js.map +1 -1
  49. package/dist/components/Slide/Slide.cjs.js +1 -1
  50. package/dist/components/Slide/Slide.cjs.js.map +1 -1
  51. package/dist/components/Slide/Slide.d.ts +13 -0
  52. package/dist/components/Slide/Slide.es.js +374 -255
  53. package/dist/components/Slide/Slide.es.js.map +1 -1
  54. package/dist/components/Slide/Slide.stories.d.ts +21 -1
  55. package/dist/components/Slide/index.d.ts +3 -3
  56. package/dist/components/Slide/types.d.ts +6 -6
  57. package/dist/components/Slide/useSlide.cjs.js +1 -1
  58. package/dist/components/Slide/useSlide.cjs.js.map +1 -1
  59. package/dist/components/Slide/useSlide.d.ts +4 -1
  60. package/dist/components/Slide/useSlide.es.js +115 -81
  61. package/dist/components/Slide/useSlide.es.js.map +1 -1
  62. package/dist/components/Slide/useWakePlayerFromIframe.cjs.js +2 -0
  63. package/dist/components/Slide/useWakePlayerFromIframe.cjs.js.map +1 -0
  64. package/dist/components/Slide/useWakePlayerFromIframe.d.ts +7 -0
  65. package/dist/components/Slide/useWakePlayerFromIframe.es.js +89 -0
  66. package/dist/components/Slide/useWakePlayerFromIframe.es.js.map +1 -0
  67. package/dist/components/index.d.ts +4 -2
  68. package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
  69. package/dist/components/ui/inputGroup/textarea.es.js +1 -1
  70. package/dist/index.cjs.js +1 -1
  71. package/dist/index.es.js +24 -22
  72. package/dist/lib/interaction-defaults.cjs.js +2 -0
  73. package/dist/lib/interaction-defaults.cjs.js.map +1 -0
  74. package/dist/lib/interaction-defaults.es.js +106 -0
  75. package/dist/lib/interaction-defaults.es.js.map +1 -0
  76. package/dist/lib/sandboxInteraction.cjs.js +2 -0
  77. package/dist/lib/sandboxInteraction.cjs.js.map +1 -0
  78. package/dist/lib/sandboxInteraction.d.ts +8 -0
  79. package/dist/lib/sandboxInteraction.es.js +12 -0
  80. package/dist/lib/sandboxInteraction.es.js.map +1 -0
  81. package/dist/markdown-flow-ui-lib.css +1 -1
  82. package/dist/renderer.cjs.js +1 -1
  83. package/dist/renderer.d.ts +5 -3
  84. package/dist/renderer.es.js +18 -16
  85. package/package.json +17 -2
  86. package/dist/components/Slide/interaction-defaults.cjs.js +0 -2
  87. package/dist/components/Slide/interaction-defaults.cjs.js.map +0 -1
  88. package/dist/components/Slide/interaction-defaults.es.js +0 -85
  89. package/dist/components/Slide/interaction-defaults.es.js.map +0 -1
  90. /package/dist/{components/Slide → lib}/interaction-defaults.d.ts +0 -0
@@ -1,118 +1,247 @@
1
- import { j as u } from "../../_virtual/jsx-runtime.es.js";
2
- import se, { useRef as d, useState as A, useCallback as ve, useEffect as C } from "react";
3
- import { createRoot as xe } from "react-dom/client";
4
- import Ee from "./SandboxApp.es.js";
5
- import { splitContentSegments as ye } from "./utils/split-content.es.js";
6
- import Ce from "./ContentRender.es.js";
7
- import Re from "../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/lucide-react@0.525.0_react@19.0.1/node_modules/lucide-react/dist/esm/icons/loader-circle.es.js";
8
- let G = null;
9
- const ce = () => (G || (G = import("./blackboard-vendor.es.js").then(
10
- (s) => s.injectBlackboardLibraries
11
- )), G);
12
- typeof window < "u" && ce();
13
- const He = /<img\b[^>]*>/i, Se = 180, Te = "markdown-flow-ui:sandbox", Ae = "interaction", Me = 240, ae = (s) => s.split(/\s+/).filter(Boolean).map((n) => n.split(":").pop() || n), ie = (s) => {
14
- const n = s.trim().toLowerCase();
15
- if (!n) return null;
16
- const m = n.match(/^([0-9.]+)(vh|dvh|svh|lvh)$/i);
17
- return m ? `${m[1]}${m[2].toLowerCase()}` : null;
18
- }, le = (s) => {
19
- if (!s.trim()) return null;
20
- const n = ae(s);
21
- if (n.includes("h-screen") || n.includes("h-dvh"))
1
+ import { j as w } from "../../_virtual/jsx-runtime.es.js";
2
+ import R, { useRef as d, useState as V, useCallback as Ve, useEffect as C } from "react";
3
+ import { createRoot as Fe } from "react-dom/client";
4
+ import Pe from "./SandboxApp.es.js";
5
+ import { splitContentSegments as ke } from "./utils/split-content.es.js";
6
+ import Oe from "./ContentRender.es.js";
7
+ import { SANDBOX_INTERACTION_MESSAGE_TYPE as De, SANDBOX_INTERACTION_MESSAGE_SOURCE as Be } from "../../lib/sandboxInteraction.es.js";
8
+ let te = null;
9
+ const be = () => (te || (te = import("./blackboard-vendor.es.js").then(
10
+ (e) => e.injectBlackboardLibraries
11
+ )), te);
12
+ typeof window < "u" && be();
13
+ const Le = /<img\b[^>]*>/i, $e = 180, je = 240, ze = /<img\b[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*>/gi, fe = /* @__PURE__ */ new Map(), $ = /* @__PURE__ */ new Set(), Ge = (e) => {
14
+ const t = Array.from(e.matchAll(ze));
15
+ return Array.from(
16
+ new Set(
17
+ t.map((n) => n[1]?.trim()).filter((n) => !!n)
18
+ )
19
+ );
20
+ }, qe = (e) => {
21
+ if (!e)
22
+ return Promise.resolve();
23
+ const t = fe.get(e);
24
+ if (t)
25
+ return t;
26
+ const n = new Promise((s) => {
27
+ if (typeof window > "u") {
28
+ $.add(e), s();
29
+ return;
30
+ }
31
+ const o = new window.Image();
32
+ o.decoding = "sync", o.loading = "eager", o.fetchPriority = "high";
33
+ const l = () => {
34
+ (typeof o.decode == "function" ? o.decode().catch(() => {
35
+ }) : Promise.resolve()).finally(() => {
36
+ $.add(e), s();
37
+ });
38
+ };
39
+ o.onload = () => {
40
+ l();
41
+ }, o.onerror = () => {
42
+ $.add(e), s();
43
+ }, o.src = e, o.complete && o.naturalWidth > 0 && l();
44
+ });
45
+ return fe.set(e, n), n;
46
+ }, ge = (e = []) => Promise.allSettled(e.map((t) => qe(t))), we = (e) => e.split(/\s+/).filter(Boolean).map((t) => t.split(":").pop() || t), j = (e) => {
47
+ const t = e.trim().toLowerCase();
48
+ if (!t) return null;
49
+ const n = t.match(/^([0-9.]+)(vh|dvh|svh|lvh)$/i);
50
+ return n ? `${n[1]}${n[2].toLowerCase()}` : null;
51
+ }, ne = (e) => {
52
+ if (!e.trim()) return null;
53
+ const t = we(e);
54
+ if (t.includes("h-screen") || t.includes("h-dvh"))
22
55
  return "100dvh";
23
- if (n.includes("h-svh"))
56
+ if (t.includes("h-svh"))
24
57
  return "100svh";
25
- if (n.includes("h-lvh"))
58
+ if (t.includes("h-lvh"))
26
59
  return "100lvh";
27
- const m = n.find(
28
- (M) => /^h-\[[0-9.]+(vh|dvh|svh|lvh)\]$/i.test(M)
60
+ const n = t.find(
61
+ (o) => /^h-\[[0-9.]+(vh|dvh|svh|lvh)\]$/i.test(o)
62
+ );
63
+ if (!n) return null;
64
+ const s = n.match(/^h-\[([0-9.]+)(vh|dvh|svh|lvh)\]$/i);
65
+ return s ? `${s[1]}${s[2].toLowerCase()}` : null;
66
+ }, Xe = /* @__PURE__ */ new Set([
67
+ "base",
68
+ "link",
69
+ "meta",
70
+ "script",
71
+ "style",
72
+ "template",
73
+ "title"
74
+ ]), ve = (e) => !Xe.has(e.tagName.toLowerCase()), Ue = (e) => Array.from(e.childNodes).find(
75
+ (t) => t.nodeType === Node.ELEMENT_NODE && ve(t)
76
+ ) || null, We = (e) => {
77
+ const t = [];
78
+ let n = Ue(e);
79
+ for (; n; ) {
80
+ t.push(n);
81
+ const s = Array.from(n.children).filter(
82
+ (o) => ve(o)
83
+ );
84
+ if (s.length !== 1)
85
+ break;
86
+ n = s[0];
87
+ }
88
+ return t;
89
+ }, Ye = (e) => {
90
+ const t = e.getAttribute("height"), n = t ? j(t) : null;
91
+ if (n)
92
+ return n;
93
+ const s = e.getAttribute("style")?.match(/\bheight\s*:\s*([^;]+)/i)?.[1] || null, o = s ? j(s) : null;
94
+ return o || ne(
95
+ e.getAttribute("class") || ""
29
96
  );
30
- if (!m) return null;
31
- const p = m.match(/^h-\[([0-9.]+)(vh|dvh|svh|lvh)\]$/i);
32
- return p ? `${p[1]}${p[2].toLowerCase()}` : null;
33
- }, Oe = ({
34
- content: s,
35
- type: n,
36
- className: m,
37
- loadingText: p,
38
- styleLoadingText: M,
39
- scriptLoadingText: U,
40
- fullScreenButtonText: j,
41
- hideFullScreen: W = !1,
42
- mode: h = "content"
97
+ }, He = (e) => e === "100vh" || e === "100dvh" || e === "100svh" || e === "100lvh", Ee = (e) => {
98
+ const t = We(e);
99
+ let n = null, s = !1;
100
+ return t.forEach((o) => {
101
+ const l = Ye(o);
102
+ !n && l && (n = l), He(l) && (s = !0);
103
+ }), {
104
+ viewportHeightCss: n,
105
+ hasFullViewportHeight: s
106
+ };
107
+ }, Ze = (e) => {
108
+ const t = e.trim();
109
+ if (!t)
110
+ return {
111
+ viewportHeightCss: null,
112
+ hasFullViewportHeight: !1
113
+ };
114
+ const s = t.match(/^<([a-zA-Z][\w:-]*)(\s[^>]*?)?>/)?.[2] || "", o = s.match(/\bheight\s*=\s*["']([^"']+)["']/i)?.[1], m = s.match(/\bstyle\s*=\s*["']([^"']+)["']/i)?.[1]?.match(
115
+ /\bheight\s*:\s*([^;]+)/i
116
+ )?.[1], S = s.match(/\bclass\s*=\s*["']([^"']+)["']/i)?.[1], h = (o ? j(o) : null) || (m ? j(m) : null) || (S ? ne(S) : null);
117
+ return {
118
+ viewportHeightCss: h,
119
+ hasFullViewportHeight: He(h)
120
+ };
121
+ }, pe = (e) => {
122
+ const t = e.trim();
123
+ if (!t)
124
+ return {
125
+ viewportHeightCss: null,
126
+ hasFullViewportHeight: !1
127
+ };
128
+ if (typeof document > "u")
129
+ return Ze(t);
130
+ const n = document.createElement("template");
131
+ return n.innerHTML = t, Ee(n.content);
132
+ }, Je = (e) => e.split(/\s+/).filter(Boolean).map((t) => {
133
+ const n = t.split(":");
134
+ return n[n.length - 1] !== "h-screen" ? t : (n[n.length - 1] = "h-full", n.join(":"));
135
+ }).join(" "), Ke = (e, t) => !t || !e.trim() ? e : e.replace(
136
+ /^(\s*<[a-zA-Z][\w:-]*)(\s[^>]*?)?>/,
137
+ (n, s, o = "") => {
138
+ const l = o.match(/\bclass\s*=\s*(["'])([^"']*)\1/i);
139
+ if (!l)
140
+ return n;
141
+ const m = Je(l[2]);
142
+ return m === l[2] ? n : `${s}${o.replace(
143
+ l[0],
144
+ `class=${l[1]}${m}${l[1]}`
145
+ )}>`;
146
+ }
147
+ ), it = ({
148
+ content: e,
149
+ type: t,
150
+ className: n,
151
+ loadingText: s,
152
+ styleLoadingText: o,
153
+ scriptLoadingText: l,
154
+ fullScreenButtonText: m,
155
+ hideFullScreen: S = !1,
156
+ mode: h = "content",
157
+ replaceRootScreenHeightWithFull: F = !1
43
158
  }) => {
44
- const X = d(null), E = d(null), _ = d(null), Y = d(null), D = d(() => {
45
- }), [ue, de] = A(480), Z = d(0), [J, he] = A(0), [me, fe] = A(!1), [L, O] = A(
46
- n !== "sandbox"
47
- ), B = h === "blackboard", F = d(""), r = se.useMemo(() => {
48
- const e = ye(s).filter((l) => l.type === "sandbox");
49
- return (h === "blackboard" ? e[e.length - 1]?.value || "" : e.map((l) => l.value).join(`
159
+ const re = d(null), y = d(null), z = d(null), oe = d(null), G = d(() => {
160
+ }), [xe, Ce] = V(480), se = d(0), [ie, ye] = V(0), [Ae, Re] = V(!1), [, q] = V(!0), Se = t === "sandbox", X = h === "blackboard", U = d(""), P = R.useMemo(() => {
161
+ const r = ke(e).filter((p) => p.type === "sandbox");
162
+ return (h === "blackboard" ? r[r.length - 1]?.value || "" : r.map((p) => p.value).join(`
50
163
  `)) || "";
51
- }, [s, h]), [k, K] = A(r), Q = d(r), z = d(r), R = d(null), y = ve((t) => {
164
+ }, [e, h]), c = R.useMemo(
165
+ () => Ke(
166
+ P,
167
+ F
168
+ ),
169
+ [P, F]
170
+ ), T = R.useMemo(
171
+ () => Ge(c),
172
+ [c]
173
+ ), le = R.useMemo(
174
+ () => pe(P),
175
+ [P]
176
+ ), ce = R.useMemo(
177
+ () => F && le.hasFullViewportHeight,
178
+ [le.hasFullViewportHeight, F]
179
+ ), [k, W] = V(
180
+ c
181
+ ), ae = d(c), Y = d(c), M = d(null), I = d(null), Z = d(null), J = d(0), A = Ve((i) => {
52
182
  if (typeof window > "u")
53
183
  return;
54
- const e = Date.now();
55
- e - Z.current < Me || (Z.current = e, window.postMessage(
184
+ const r = Date.now();
185
+ r - se.current < je || (se.current = r, window.postMessage(
56
186
  {
57
- source: Te,
58
- type: Ae,
59
- eventType: t
187
+ source: Be,
188
+ type: De,
189
+ eventType: i
60
190
  },
61
191
  window.location.origin
62
192
  ));
63
- }, []), $ = () => {
64
- R.current !== null && (window.clearTimeout(R.current), R.current = null);
193
+ }, []), ue = () => {
194
+ M.current !== null && (window.clearTimeout(M.current), M.current = null);
195
+ }, Te = () => {
196
+ I.current !== null && (window.cancelAnimationFrame(I.current), I.current = null), Z.current !== null && (window.cancelAnimationFrame(Z.current), Z.current = null);
65
197
  };
66
198
  C(
67
199
  () => () => {
68
- $();
200
+ ue(), Te();
69
201
  },
70
202
  []
71
203
  ), C(() => {
72
- const t = Q.current;
73
- Q.current = r;
74
- const e = !!t && r.length > t.length && r.startsWith(t), i = He.test(r);
75
- if (!(e && i)) {
76
- $(), z.current = r, K(r);
204
+ ge(T);
205
+ }, [T]), C(() => {
206
+ const i = ae.current;
207
+ ae.current = c;
208
+ const r = !!i && c.length > i.length && c.startsWith(i), g = Le.test(
209
+ c
210
+ ), p = r && g && T.some(
211
+ (v) => !$.has(v)
212
+ ), O = r && g;
213
+ if (Y.current = c, ue(), p) {
214
+ const v = J.current + 1;
215
+ J.current = v, ge(T).then(() => {
216
+ J.current === v && W(Y.current);
217
+ });
77
218
  return;
78
219
  }
79
- z.current = r, $(), R.current = window.setTimeout(() => {
80
- K(z.current), R.current = null;
81
- }, Se);
82
- }, [r]);
83
- const ee = se.useMemo(() => {
84
- const t = k.trim();
85
- if (!t) return null;
86
- const e = t.match(/^<([a-zA-Z][\w:-]*)(\s[^>]*?)?>/);
87
- if (!e) return null;
88
- const i = e[2] || "", l = i.match(/\bheight\s*=\s*["']([^"']+)["']/i);
89
- if (l) {
90
- const f = ie(l[1]);
91
- if (f) return f;
92
- }
93
- const S = i.match(/\bstyle\s*=\s*["']([^"']+)["']/i)?.[1]?.match(
94
- /\bheight\s*:\s*([^;]+)/i
95
- )?.[1];
96
- if (S) {
97
- const f = ie(S);
98
- if (f) return f;
220
+ if (!O) {
221
+ W(c);
222
+ return;
99
223
  }
100
- const g = i.match(/\bclass\s*=\s*["']([^"']+)["']/i)?.[1];
101
- return g ? le(g) : null;
102
- }, [k]), te = !!ee, ne = n === "sandbox", H = B && n === "sandbox" ? ee ?? `${ue}px` : void 0;
224
+ M.current = window.setTimeout(() => {
225
+ W(Y.current), M.current = null;
226
+ }, $e);
227
+ }, [T, c]);
228
+ const de = R.useMemo(
229
+ () => pe(k).viewportHeightCss,
230
+ [k]
231
+ ), he = !!de, N = X && t === "sandbox" ? ce ? "100%" : de ?? `${xe}px` : void 0;
103
232
  C(() => {
104
233
  if (h !== "blackboard") {
105
- F.current = r;
234
+ U.current = c;
106
235
  return;
107
236
  }
108
- const t = F.current;
109
- !(t && r.startsWith(t)) && t && he((i) => i + 1), F.current = r;
110
- }, [r, h]), C(() => {
111
- const t = E.current;
112
- if (!t) return;
113
- const e = t.contentDocument;
114
- if (!e) return;
115
- e.open(), e.write(`<!DOCTYPE html>
237
+ const i = U.current;
238
+ !(i && c.startsWith(i)) && i && ye((g) => g + 1), U.current = c;
239
+ }, [h, c]), C(() => {
240
+ const i = y.current;
241
+ if (!i) return;
242
+ const r = i.contentDocument;
243
+ if (!r) return;
244
+ r.open(), r.write(`<!DOCTYPE html>
116
245
  <html${h === "blackboard" ? ' style="height: 100%;"' : ""}>
117
246
  <head>
118
247
  <meta charset="utf-8" />
@@ -126,182 +255,182 @@ const He = /<img\b[^>]*>/i, Se = 180, Te = "markdown-flow-ui:sandbox", Ae = "int
126
255
  <body>
127
256
  <div id="root"></div>
128
257
  </body>
129
- </html>`), e.close(), Y.current = e;
130
- const i = B && n === "sandbox", l = () => y("pointerdown"), V = () => y("mousedown"), S = () => y("touchstart");
131
- i && (e.addEventListener("pointerdown", l, !0), e.addEventListener("mousedown", V, !0), e.addEventListener("touchstart", S, !0));
132
- const g = e.getElementById("root");
133
- if (!g) return;
134
- const f = xe(g);
135
- _.current = f;
136
- let T = !1;
137
- const oe = (c, b) => {
138
- const o = c.trim().toLowerCase();
139
- if (!o) return null;
140
- const a = Number.parseFloat(o);
141
- return Number.isNaN(a) ? null : /(dvh|svh|lvh|vh)$/i.test(o) ? a / 100 * b : o.endsWith("px") || /^[0-9.]+$/.test(o) ? a : null;
142
- }, ge = (c, b) => {
143
- if (!c.trim()) return null;
144
- const o = le(c);
145
- if (o)
146
- return oe(o, b);
147
- const w = ae(c).find(
148
- (I) => /^h-\[[0-9.]+px\]$/i.test(I)
258
+ </html>`), r.close(), oe.current = r;
259
+ const g = X && t === "sandbox", p = () => A("pointerdown"), O = () => A("mousedown"), v = () => A("touchstart");
260
+ g && (r.addEventListener("pointerdown", p, !0), r.addEventListener("mousedown", O, !0), r.addEventListener("touchstart", v, !0));
261
+ const D = r.getElementById("root");
262
+ if (!D) return;
263
+ const me = Fe(D);
264
+ z.current = me;
265
+ let _ = !1;
266
+ const K = (a, b) => {
267
+ const u = a.trim().toLowerCase();
268
+ if (!u) return null;
269
+ const H = Number.parseFloat(u);
270
+ return Number.isNaN(H) ? null : /(dvh|svh|lvh|vh)$/i.test(u) ? H / 100 * b : u.endsWith("px") || /^[0-9.]+$/.test(u) ? H : null;
271
+ }, Ne = (a, b) => {
272
+ if (!a.trim()) return null;
273
+ const u = ne(a);
274
+ if (u)
275
+ return K(u, b);
276
+ const f = we(a).find(
277
+ (L) => /^h-\[[0-9.]+px\]$/i.test(L)
149
278
  );
150
- if (!w) return null;
151
- const v = w.match(/^h-\[([0-9.]+)px\]$/i);
152
- if (!v) return null;
153
- const x = Number.parseFloat(v[1]);
279
+ if (!f) return null;
280
+ const E = f.match(/^h-\[([0-9.]+)px\]$/i);
281
+ if (!E) return null;
282
+ const x = Number.parseFloat(E[1]);
154
283
  return Number.isNaN(x) ? null : x;
155
- }, we = () => {
156
- if (!E.current || !e.body) return null;
157
- const b = e.body.querySelector(
284
+ }, _e = () => {
285
+ if (!y.current || !r.body) return null;
286
+ const a = y.current.ownerDocument?.documentElement?.clientHeight || window.innerHeight, { viewportHeightCss: b } = Ee(r.body), u = b ? K(b, a) : null;
287
+ if (u !== null)
288
+ return Math.ceil(u);
289
+ const f = r.body.querySelector(
158
290
  ".sandbox-wrapper"
159
- )?.firstElementChild;
160
- if (!b) return null;
161
- const o = Array.from(b.children);
162
- if (o.length !== 1) return null;
163
- const a = o[0], w = a.style.height || a.getAttribute("height"), v = E.current.ownerDocument?.documentElement?.clientHeight || window.innerHeight, x = w ? oe(w, v) : null;
291
+ )?.querySelector(
292
+ ".sandbox-container > *"
293
+ );
294
+ if (!f) return null;
295
+ const E = f.style.height || f.getAttribute("height"), x = E ? K(E, a) : null;
164
296
  if (x !== null)
165
297
  return Math.ceil(x);
166
- const I = ge(
167
- a.getAttribute("class") || "",
168
- v
298
+ const L = Ne(
299
+ f.getAttribute("class") || "",
300
+ a
169
301
  );
170
- return I !== null ? Math.ceil(I) : null;
171
- }, P = () => {
172
- if (!E.current || !e.body) return;
173
- const c = e.body.getBoundingClientRect(), b = e.documentElement?.getBoundingClientRect(), o = c.height, a = b?.height || 0, w = Math.max(o, a), v = we(), x = Math.max(
302
+ return L !== null ? Math.ceil(L) : null;
303
+ }, Q = () => {
304
+ if (!y.current || !r.body) return;
305
+ const a = r.body.getBoundingClientRect(), b = r.documentElement?.getBoundingClientRect(), u = a.height, H = b?.height || 0, f = Math.max(u, H), E = _e(), x = Math.max(
174
306
  200,
175
- v ?? Math.ceil(w)
307
+ E ?? Math.ceil(f)
176
308
  );
177
- de(x);
178
- }, N = () => {
309
+ Ce(x);
310
+ }, B = () => {
179
311
  requestAnimationFrame(() => {
180
- T || P();
312
+ _ || Q();
181
313
  });
182
314
  };
183
- D.current = N, P(), N(), ne ? ce().then((c) => {
184
- T || (c(e), requestAnimationFrame(() => {
185
- T || (O(!0), N());
315
+ G.current = B, Q(), B(), Se ? be().then((a) => {
316
+ _ || (a(r), requestAnimationFrame(() => {
317
+ _ || (q(!0), B());
186
318
  }));
187
319
  }).catch(() => {
188
- T || (O(!0), N());
189
- }) : O(!0);
190
- const q = new ResizeObserver(() => P());
191
- return q.observe(e.body), g && q.observe(g), () => {
192
- T = !0, q.disconnect(), i && (e.removeEventListener("pointerdown", l, !0), e.removeEventListener("mousedown", V, !0), e.removeEventListener("touchstart", S, !0)), setTimeout(() => {
193
- f.unmount(), _.current = null, Y.current = null, D.current = () => {
320
+ _ || (q(!0), B());
321
+ }) : q(!0);
322
+ const ee = new ResizeObserver(() => Q());
323
+ return ee.observe(r.body), D && ee.observe(D), () => {
324
+ _ = !0, ee.disconnect(), g && (r.removeEventListener("pointerdown", p, !0), r.removeEventListener("mousedown", O, !0), r.removeEventListener("touchstart", v, !0)), setTimeout(() => {
325
+ me.unmount(), z.current = null, oe.current = null, G.current = () => {
194
326
  };
195
327
  }, 0);
196
328
  };
197
329
  }, []), C(() => {
198
- const t = () => {
199
- fe(!!document.fullscreenElement);
330
+ const i = () => {
331
+ Re(!!document.fullscreenElement);
200
332
  };
201
- return document.addEventListener("fullscreenchange", t), () => document.removeEventListener("fullscreenchange", t);
333
+ return document.addEventListener("fullscreenchange", i), () => document.removeEventListener("fullscreenchange", i);
202
334
  }, []);
203
- const be = () => {
204
- const t = X.current || E.current;
205
- if (t) {
335
+ const Me = () => {
336
+ const i = re.current || y.current;
337
+ if (i) {
206
338
  if (document.fullscreenElement) {
207
339
  document.exitFullscreen().catch(() => {
208
340
  });
209
341
  return;
210
342
  }
211
- t.requestFullscreen && t.requestFullscreen().catch(() => {
343
+ i.requestFullscreen && i.requestFullscreen().catch(() => {
212
344
  });
213
345
  }
214
346
  };
215
347
  C(() => {
216
- const t = _.current;
217
- !t || !L || (t.render(
218
- /* @__PURE__ */ u.jsx(
219
- Ee,
348
+ const i = z.current;
349
+ i && (i.render(
350
+ /* @__PURE__ */ w.jsx(
351
+ Pe,
220
352
  {
221
353
  html: k,
222
- loadingText: p,
223
- styleLoadingText: M,
224
- scriptLoadingText: U,
225
- fullScreenButtonText: j,
226
- hideFullScreen: W,
227
- resetToken: J,
228
- hasRootVhHeight: te,
229
- mode: h
354
+ loadingText: s,
355
+ styleLoadingText: o,
356
+ scriptLoadingText: l,
357
+ fullScreenButtonText: m,
358
+ hideFullScreen: S,
359
+ resetToken: ie,
360
+ hasRootVhHeight: he,
361
+ mode: h,
362
+ stretchRootHeight: ce
230
363
  }
231
364
  )
232
- ), requestAnimationFrame(() => D.current?.()));
365
+ ), I.current = window.requestAnimationFrame(() => {
366
+ G.current?.(), I.current = null;
367
+ }));
233
368
  }, [
234
369
  k,
235
- p,
236
- M,
237
- U,
238
- j,
239
- J,
240
- h,
241
- L
370
+ s,
371
+ o,
372
+ l,
373
+ m,
374
+ ie,
375
+ h
242
376
  ]);
243
- const pe = [
377
+ const Ie = [
244
378
  "w-full relative content-render-iframe-sandbox",
245
- B ? "h-full overflow-auto flex flex-col" : "aspect-[16/9] overflow-hidden flex items-center justify-center"
246
- ].filter(Boolean).join(" "), re = ne && !L;
247
- return /* @__PURE__ */ u.jsxs(
379
+ X ? "h-full overflow-auto flex flex-col" : "aspect-[16/9] overflow-hidden flex items-center justify-center"
380
+ ].filter(Boolean).join(" ");
381
+ return /* @__PURE__ */ w.jsxs(
248
382
  "div",
249
383
  {
250
- ref: X,
251
- "data-root-vh": te ? "true" : "false",
252
- className: pe,
253
- style: H ? {
254
- height: H,
255
- minHeight: H
384
+ ref: re,
385
+ "data-root-vh": he ? "true" : "false",
386
+ className: Ie,
387
+ style: N ? {
388
+ height: N,
389
+ minHeight: N
256
390
  } : void 0,
257
391
  children: [
258
- !W && /* @__PURE__ */ u.jsx(
392
+ !S && /* @__PURE__ */ w.jsx(
259
393
  "button",
260
394
  {
261
395
  type: "button",
262
- onClick: be,
396
+ onClick: Me,
263
397
  className: "absolute top-2 right-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer",
264
- children: me ? "退出全屏" : j || "全屏浏览"
398
+ children: Ae ? "退出全屏" : m || "全屏浏览"
265
399
  }
266
400
  ),
267
- h === "blackboard" && n === "markdown" ? /* @__PURE__ */ u.jsx(
401
+ h === "blackboard" && t === "markdown" ? /* @__PURE__ */ w.jsx(
268
402
  "div",
269
403
  {
270
- onMouseDown: () => y("mousedown"),
271
- onPointerDown: () => y("pointerdown"),
272
- onTouchStart: () => y("touchstart"),
273
- children: /* @__PURE__ */ u.jsx(Ce, { content: s })
404
+ onMouseDown: () => A("mousedown"),
405
+ onPointerDown: () => A("pointerdown"),
406
+ onTouchStart: () => A("touchstart"),
407
+ children: /* @__PURE__ */ w.jsx(Oe, { content: e })
274
408
  }
275
- ) : /* @__PURE__ */ u.jsxs(u.Fragment, { children: [
276
- /* @__PURE__ */ u.jsx(
409
+ ) : /* @__PURE__ */ w.jsxs(w.Fragment, { children: [
410
+ null,
411
+ /* @__PURE__ */ w.jsx(
277
412
  "iframe",
278
413
  {
279
- ref: E,
414
+ ref: y,
280
415
  sandbox: "allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox",
281
416
  allow: "fullscreen",
282
417
  allowFullScreen: !0,
283
- className: [m, "w-full h-full mx-auto my-auto block"].filter(Boolean).join(" "),
418
+ className: [n, "w-full h-full mx-auto my-auto block"].filter(Boolean).join(" "),
284
419
  style: {
285
- height: H ?? "100%",
286
- minHeight: H,
420
+ height: N ?? "100%",
421
+ minHeight: N,
287
422
  margin: "auto",
288
- visibility: re ? "hidden" : "visible"
423
+ visibility: "visible"
289
424
  }
290
425
  }
291
426
  ),
292
- re ? /* @__PURE__ */ u.jsx("div", { className: "pointer-events-none absolute inset-0 z-20 flex items-center justify-center", children: /* @__PURE__ */ u.jsx(
293
- Re,
294
- {
295
- "aria-label": p || "Preparing sandbox styles",
296
- className: "text-primary h-7 w-7 animate-spin"
297
- }
298
- ) }) : null
427
+ null
299
428
  ] })
300
429
  ]
301
430
  }
302
431
  );
303
432
  };
304
433
  export {
305
- Oe as default
434
+ it as default
306
435
  };
307
436
  //# sourceMappingURL=IframeSandbox.es.js.map