markdown-flow-ui 0.1.92 → 0.1.93-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js.map +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.cjs.js +6 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.cjs.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.es.js +350 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.es.js.map +1 -0
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/c4Diagram-YG6GDRKO.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-S3R3BYOJ.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/chunk-TZMSLE5B.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/ganttDiagram-LVOFAZNH.es.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/mermaid@11.12.1/node_modules/mermaid/dist/chunks/mermaid.core/sequenceDiagram-WL72ISMW.es.js +1 -1
- package/dist/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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/remark-flow@0.1.6/node_modules/remark-flow/dist/index.es.js +1 -1
- 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
- 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
- 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
- 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
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.cjs.js +1 -1
- package/dist/Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.es.js +1 -1
- package/dist/_virtual/index.cjs10.js +1 -1
- package/dist/_virtual/index.cjs2.js +1 -1
- package/dist/_virtual/index.cjs3.js +1 -1
- package/dist/_virtual/index.cjs4.js +1 -1
- package/dist/_virtual/index.cjs7.js +1 -1
- package/dist/_virtual/index.cjs8.js +1 -1
- package/dist/_virtual/index.es10.js +2 -2
- package/dist/_virtual/index.es2.js +5 -2
- package/dist/_virtual/index.es2.js.map +1 -1
- package/dist/_virtual/index.es3.js +2 -4
- package/dist/_virtual/index.es3.js.map +1 -1
- package/dist/_virtual/index.es4.js +4 -5
- package/dist/_virtual/index.es4.js.map +1 -1
- package/dist/_virtual/index.es7.js +2 -3
- package/dist/_virtual/index.es7.js.map +1 -1
- package/dist/_virtual/index.es8.js +3 -2
- package/dist/_virtual/index.es8.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.cjs.js +2 -2
- package/dist/components/ContentRender/ContentRender.cjs.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.es.js +111 -104
- package/dist/components/ContentRender/ContentRender.es.js.map +1 -1
- package/dist/components/ContentRender/ContentRender.stories.d.ts +1 -0
- package/dist/components/ContentRender/IframeSandbox.cjs.js +6 -5
- package/dist/components/ContentRender/IframeSandbox.cjs.js.map +1 -1
- package/dist/components/ContentRender/IframeSandbox.es.js +104 -98
- package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
- package/dist/components/ContentRender/SandboxApp.cjs.js +3 -2
- package/dist/components/ContentRender/SandboxApp.cjs.js.map +1 -1
- package/dist/components/ContentRender/SandboxApp.es.js +92 -84
- package/dist/components/ContentRender/SandboxApp.es.js.map +1 -1
- package/dist/components/ContentRender/blackboard/blackboard-runtime.cjs.js +5 -0
- package/dist/components/ContentRender/blackboard/blackboard-runtime.cjs.js.map +1 -0
- package/dist/components/ContentRender/blackboard/blackboard-runtime.d.ts +18 -0
- package/dist/components/ContentRender/blackboard/blackboard-runtime.es.js +137 -0
- package/dist/components/ContentRender/blackboard/blackboard-runtime.es.js.map +1 -0
- package/dist/components/ContentRender/blackboard/diff-parser.cjs.js +2 -0
- package/dist/components/ContentRender/blackboard/diff-parser.cjs.js.map +1 -0
- package/dist/components/ContentRender/blackboard/diff-parser.d.ts +8 -0
- package/dist/components/ContentRender/blackboard/diff-parser.es.js +132 -0
- package/dist/components/ContentRender/blackboard/diff-parser.es.js.map +1 -0
- package/dist/components/ContentRender/blackboard/diff-parser.test.d.ts +1 -0
- package/dist/components/ContentRender/blackboard-vendor.cjs.js +2 -0
- package/dist/components/ContentRender/blackboard-vendor.cjs.js.map +1 -0
- package/dist/components/ContentRender/blackboard-vendor.d.ts +5 -0
- package/dist/components/ContentRender/blackboard-vendor.es.js +15 -0
- package/dist/components/ContentRender/blackboard-vendor.es.js.map +1 -0
- package/dist/components/ContentRender/index.cjs.js +1 -1
- package/dist/components/ContentRender/index.es.js +1 -0
- package/dist/components/ContentRender/index.es.js.map +1 -1
- package/dist/components/ContentRender/utils/split-content.cjs.js +2 -2
- package/dist/components/ContentRender/utils/split-content.cjs.js.map +1 -1
- package/dist/components/ContentRender/utils/split-content.es.js +118 -109
- package/dist/components/ContentRender/utils/split-content.es.js.map +1 -1
- package/dist/components/ContentRender/vendor/daisyui-v4.min.css.cjs.js +22 -0
- package/dist/components/ContentRender/vendor/daisyui-v4.min.css.cjs.js.map +1 -0
- package/dist/components/ContentRender/vendor/daisyui-v4.min.css.es.js +25 -0
- package/dist/components/ContentRender/vendor/daisyui-v4.min.css.es.js.map +1 -0
- package/dist/components/ContentRender/vendor/gsap-v3.min.cjs.js +12 -0
- package/dist/components/ContentRender/vendor/gsap-v3.min.cjs.js.map +1 -0
- package/dist/components/ContentRender/vendor/gsap-v3.min.es.js +15 -0
- package/dist/components/ContentRender/vendor/gsap-v3.min.es.js.map +1 -0
- package/dist/components/ContentRender/vendor/tailwindcss-v3.min.cjs.js +2 -0
- package/dist/components/ContentRender/vendor/tailwindcss-v3.min.cjs.js.map +1 -0
- package/dist/components/ContentRender/vendor/tailwindcss-v3.min.es.js +5 -0
- package/dist/components/ContentRender/vendor/tailwindcss-v3.min.es.js.map +1 -0
- package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js +1 -1
- package/dist/components/MarkdownFlow/MarkdownFlow.cjs.js.map +1 -1
- package/dist/components/MarkdownFlow/MarkdownFlow.es.js +3 -2
- package/dist/components/MarkdownFlow/MarkdownFlow.es.js.map +1 -1
- package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
- package/dist/components/ui/inputGroup/textarea.es.js +1 -1
- package/dist/markdown-flow-ui-lib.css +1 -1
- package/package.json +4 -1
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
import { j as
|
|
2
|
-
import { useRef as n, useState as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { j as E } from "../../_virtual/jsx-runtime.es.js";
|
|
2
|
+
import { useRef as n, useState as j, useEffect as L } from "react";
|
|
3
|
+
import { BlackboardRuntime as U } from "./blackboard/blackboard-runtime.es.js";
|
|
4
|
+
import X 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";
|
|
5
|
+
const re = ({
|
|
6
|
+
html: l,
|
|
7
|
+
styleLoadingText: z,
|
|
8
|
+
scriptLoadingText: W,
|
|
9
|
+
resetToken: m = 0,
|
|
10
|
+
mode: S = "content",
|
|
11
|
+
hasRootVhHeight: q = !1
|
|
11
12
|
}) => {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
},
|
|
13
|
+
const H = n(null), R = n(null), [, N] = j(!0), [V, A] = j(!1), [_, I] = j(!1), f = n([]), d = n([]), M = n(0), B = n(0), h = n(null), y = n(null), x = n(!1), g = n(!1), b = n(!1), D = n(m), o = n(null), O = 200, c = (r) => {
|
|
14
|
+
r.current && (clearTimeout(r.current), r.current = null);
|
|
15
|
+
}, T = (r, s, a, w) => {
|
|
16
|
+
const u = performance.now() - a.current, C = Math.max(0, O - u);
|
|
17
|
+
c(s), s.current = window.setTimeout(() => {
|
|
18
|
+
r(!1), w?.(), s.current = null;
|
|
19
|
+
}, C);
|
|
19
20
|
};
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
if (!
|
|
21
|
+
L(() => {
|
|
22
|
+
const r = R.current?.ownerDocument;
|
|
23
|
+
if (!r) return;
|
|
23
24
|
const s = "sandbox-spinner-style";
|
|
24
|
-
let
|
|
25
|
-
|
|
25
|
+
let a = r.getElementById(s);
|
|
26
|
+
a || (a = r.createElement("style"), a.id = s, r.head?.appendChild(a)), a.textContent = `
|
|
26
27
|
@keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }
|
|
27
28
|
.sandbox-wrapper { align-items: center; }
|
|
28
29
|
.sandbox-container { width: 100%; }
|
|
@@ -31,116 +32,123 @@ const $ = ({
|
|
|
31
32
|
@media (max-width: 640px) {
|
|
32
33
|
.sandbox-wrapper { align-items: stretch; }
|
|
33
34
|
.sandbox-wrapper[data-root-vh="true"] .sandbox-container > :first-child { height: auto !important; }
|
|
35
|
+
.sandbox-wrapper[data-root-vh="true"] .sandbox-container > #ppt-container > :first-child { height: auto !important; }
|
|
34
36
|
}
|
|
35
37
|
`;
|
|
36
|
-
}, []),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
}, []), L(() => {
|
|
39
|
+
const r = R.current;
|
|
40
|
+
if (!r) return;
|
|
41
|
+
if (m !== D.current && (b.current = !1, D.current = m, o.current?.reset()), c(h), c(y), x.current = !1, g.current = !1, A(!1), I(!1), S === "blackboard") {
|
|
42
|
+
f.current.forEach((t) => t.remove()), f.current = [], d.current.forEach((t) => t.remove()), d.current = [], o.current || (o.current = new U(r)), o.current.update(l);
|
|
43
|
+
const e = o.current.hasRenderedContent();
|
|
44
|
+
b.current = e, N(!e);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
o.current && (o.current.reset(), o.current = null);
|
|
48
|
+
const s = r.ownerDocument, a = s?.body;
|
|
49
|
+
if (!a) return;
|
|
50
|
+
f.current.forEach((e) => e.remove()), f.current = [], d.current.forEach((e) => e.remove()), d.current = [];
|
|
51
|
+
const w = b.current;
|
|
52
|
+
N(!w), r.innerHTML = "";
|
|
53
|
+
const u = document.createElement("div");
|
|
54
|
+
u.innerHTML = l;
|
|
55
|
+
const C = (l.match(/<script[\s>]/gi) || []).length, J = (l.match(/<\/script>/gi) || []).length, K = C > 0 && C === J, p = [];
|
|
56
|
+
Array.from(u.querySelectorAll("style, script")).forEach((e) => {
|
|
49
57
|
if (e.tagName.toLowerCase() === "style") {
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}),
|
|
58
|
+
const t = s.createElement("style");
|
|
59
|
+
t.textContent = e.textContent || "", Array.from(e.attributes).forEach((i) => {
|
|
60
|
+
t.setAttribute(i.name, i.value);
|
|
61
|
+
}), p.push(t);
|
|
54
62
|
} else {
|
|
55
|
-
const
|
|
56
|
-
Array.from(e.attributes).forEach((
|
|
57
|
-
|
|
58
|
-
}),
|
|
63
|
+
const t = s.createElement("script");
|
|
64
|
+
Array.from(e.attributes).forEach((i) => {
|
|
65
|
+
t.setAttribute(i.name, i.value);
|
|
66
|
+
}), t.textContent = e.textContent || "", p.push(t);
|
|
59
67
|
}
|
|
60
68
|
e.remove();
|
|
61
69
|
});
|
|
62
|
-
const
|
|
70
|
+
const k = p.some(
|
|
63
71
|
(e) => e.tagName.toLowerCase() === "style"
|
|
64
|
-
),
|
|
72
|
+
), G = p.some(
|
|
65
73
|
(e) => e.tagName.toLowerCase() === "script"
|
|
66
74
|
);
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
75
|
+
k && (x.current = !0, M.current = performance.now(), c(h), A(!0)), G && (g.current = !0, B.current = performance.now(), c(y), I(!0));
|
|
76
|
+
const F = !!u.firstElementChild;
|
|
77
|
+
N(!F && !w), F && (b.current = !0);
|
|
78
|
+
const P = Array.from(u.childNodes);
|
|
79
|
+
r.append(...P), p.forEach((e) => {
|
|
72
80
|
if (e.tagName.toLowerCase() === "style") {
|
|
73
|
-
s.head?.appendChild(e),
|
|
81
|
+
s.head?.appendChild(e), f.current.push(e);
|
|
74
82
|
return;
|
|
75
83
|
}
|
|
76
|
-
if (
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
84
|
+
if (K) {
|
|
85
|
+
const t = e, i = t.textContent || "";
|
|
86
|
+
if (!t.src)
|
|
79
87
|
try {
|
|
80
|
-
new Function(
|
|
88
|
+
new Function(i);
|
|
81
89
|
} catch {
|
|
82
|
-
|
|
90
|
+
t.remove();
|
|
83
91
|
return;
|
|
84
92
|
}
|
|
85
93
|
try {
|
|
86
|
-
|
|
94
|
+
a.appendChild(t), d.current.push(t);
|
|
87
95
|
} catch {
|
|
88
|
-
|
|
96
|
+
t.remove();
|
|
89
97
|
}
|
|
90
98
|
} else
|
|
91
99
|
e.remove();
|
|
92
100
|
}), requestAnimationFrame(() => {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
101
|
+
k && T(
|
|
102
|
+
A,
|
|
103
|
+
h,
|
|
104
|
+
M,
|
|
97
105
|
() => {
|
|
98
|
-
|
|
106
|
+
x.current = !1;
|
|
99
107
|
}
|
|
100
|
-
),
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
), G && T(
|
|
109
|
+
I,
|
|
110
|
+
y,
|
|
111
|
+
B,
|
|
104
112
|
() => {
|
|
105
|
-
|
|
113
|
+
g.current = !1;
|
|
106
114
|
}
|
|
107
115
|
);
|
|
108
116
|
});
|
|
109
|
-
}, [
|
|
117
|
+
}, [l, S, m]), L(
|
|
110
118
|
() => () => {
|
|
111
|
-
|
|
119
|
+
c(h), c(y), o.current = null;
|
|
112
120
|
},
|
|
113
121
|
[]
|
|
114
122
|
);
|
|
115
|
-
const
|
|
116
|
-
return /* @__PURE__ */
|
|
123
|
+
const v = _ || g.current ? W || "Building scripts cache..." : V || x.current ? z || "Building styles..." : null, Q = S === "blackboard";
|
|
124
|
+
return /* @__PURE__ */ E.jsxs(
|
|
117
125
|
"div",
|
|
118
126
|
{
|
|
119
|
-
ref:
|
|
120
|
-
"data-root-vh":
|
|
127
|
+
ref: H,
|
|
128
|
+
"data-root-vh": q ? "true" : "false",
|
|
121
129
|
className: "sandbox-wrapper",
|
|
122
130
|
style: {
|
|
123
131
|
position: "relative",
|
|
124
132
|
width: "100%",
|
|
125
|
-
height:
|
|
133
|
+
height: Q ? "100dvh" : void 0,
|
|
126
134
|
display: "flex",
|
|
127
135
|
flexDirection: "column",
|
|
128
136
|
// if use center, too long iframe wont see header
|
|
129
137
|
justifyContent: "space-around"
|
|
130
138
|
},
|
|
131
|
-
"aria-busy": !!
|
|
139
|
+
"aria-busy": !!v,
|
|
132
140
|
children: [
|
|
133
|
-
/* @__PURE__ */
|
|
141
|
+
/* @__PURE__ */ E.jsx(
|
|
134
142
|
"div",
|
|
135
143
|
{
|
|
136
|
-
ref:
|
|
144
|
+
ref: R,
|
|
137
145
|
className: "sandbox-container",
|
|
138
146
|
style: {
|
|
139
|
-
pointerEvents:
|
|
147
|
+
pointerEvents: v ? "none" : void 0
|
|
140
148
|
}
|
|
141
149
|
}
|
|
142
150
|
),
|
|
143
|
-
|
|
151
|
+
v && /* @__PURE__ */ E.jsxs(
|
|
144
152
|
"div",
|
|
145
153
|
{
|
|
146
154
|
style: {
|
|
@@ -158,15 +166,15 @@ const $ = ({
|
|
|
158
166
|
zIndex: 20
|
|
159
167
|
},
|
|
160
168
|
children: [
|
|
161
|
-
/* @__PURE__ */
|
|
162
|
-
|
|
169
|
+
/* @__PURE__ */ E.jsx(
|
|
170
|
+
X,
|
|
163
171
|
{
|
|
164
172
|
"aria-hidden": !0,
|
|
165
173
|
size: 20,
|
|
166
174
|
style: { animation: "sandbox-spin 1s linear infinite" }
|
|
167
175
|
}
|
|
168
176
|
),
|
|
169
|
-
|
|
177
|
+
v
|
|
170
178
|
]
|
|
171
179
|
}
|
|
172
180
|
)
|
|
@@ -175,6 +183,6 @@ const $ = ({
|
|
|
175
183
|
);
|
|
176
184
|
};
|
|
177
185
|
export {
|
|
178
|
-
|
|
186
|
+
re as default
|
|
179
187
|
};
|
|
180
188
|
//# 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 { Loader2 } from \"lucide-react\";\n\nexport interface SandboxAppProps {\n html: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [, setIsWaitingFirstDiv] = useState(true);\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 @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n @media (max-width: 640px) {\n .sandbox-wrapper { align-items: stretch; }\n .sandbox-wrapper[data-root-vh=\"true\"] .sandbox-container > :first-child { height: auto !important; }\n }\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\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 setIsWaitingFirstDiv(!hasRenderedBefore);\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n container.innerHTML = \"\";\n const wrapper = document.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\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 setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.append(...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 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]);\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\n return (\n <div\n ref={wrapperRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={{\n position: \"relative\",\n width: \"100%\",\n height: isBlackboard ? \"100vh\" : undefined,\n display: \"flex\",\n flexDirection: \"column\",\n // if use center, too long iframe wont see header\n justifyContent: \"space-around\",\n }}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={{\n pointerEvents: overlayMessage ? \"none\" : undefined,\n }}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","wrapperRef","useRef","containerRef","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","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","node","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","contentNodes","scriptNode","scriptText","overlayMessage","isBlackboard","jsxs","jsx","Loader2"],"mappings":";;;AAYA,MAAMA,IAAwC,CAAC;AAAA,EAC7C,MAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,MAAAC,IAAO;AAAA,EACP,iBAAAC,IAAkB;AACpB,MAAM;AACJ,QAAMC,IAAaC,EAAuB,IAAI,GACxCC,IAAeD,EAAuB,IAAI,GAC1C,GAAGE,CAAoB,IAAIC,EAAS,EAAI,GACxC,CAACC,GAAoBC,CAAqB,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L,UAAU;AAAA,cACV,OAAO;AAAA,cACP,SAAS;AAAA,cACT,YAAY;AAAA,cACZ,gBAAgB;AAAA,cAChB,YAAY;AAAA,cACZ,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,KAAK;AAAA,cACL,eAAe;AAAA,cACf,QAAQ;AAAA,YAAA;AAAA,YAGV,UAAA;AAAA,cAAAC,gBAAAA,EAAAA;AAAAA,gBAACC;AAAAA,gBAAA;AAAA,kBACC,eAAW;AAAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;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 { Loader2 } from \"lucide-react\";\nimport { BlackboardRuntime } from \"./blackboard/blackboard-runtime\";\n\nexport interface SandboxAppProps {\n html: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n resetToken?: number;\n mode?: \"content\" | \"blackboard\";\n hasRootVhHeight?: boolean;\n}\n\nconst SandboxApp: React.FC<SandboxAppProps> = ({\n html,\n styleLoadingText,\n scriptLoadingText,\n resetToken = 0,\n mode = \"content\",\n hasRootVhHeight = false,\n}) => {\n const wrapperRef = useRef<HTMLDivElement>(null);\n const containerRef = useRef<HTMLDivElement>(null);\n const [, setIsWaitingFirstDiv] = useState(true);\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 runtimeRef = useRef<BlackboardRuntime | null>(null);\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 @keyframes sandbox-spin { from { transform: rotate(0deg);} to { transform: rotate(360deg);} }\n .sandbox-wrapper { align-items: center; }\n .sandbox-container { width: 100%; }\n .sandbox-container svg,\n .sandbox-container img { display: block; margin-left: auto; margin-right: auto; }\n @media (max-width: 640px) {\n .sandbox-wrapper { align-items: stretch; }\n .sandbox-wrapper[data-root-vh=\"true\"] .sandbox-container > :first-child { height: auto !important; }\n .sandbox-wrapper[data-root-vh=\"true\"] .sandbox-container > #ppt-container > :first-child { height: auto !important; }\n }\n `;\n }, []);\n\n useEffect(() => {\n const container = containerRef.current;\n if (!container) return;\n\n if (resetToken !== prevResetTokenRef.current) {\n hasRenderedContentRef.current = false;\n prevResetTokenRef.current = resetToken;\n runtimeRef.current?.reset();\n }\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n hasStylesRef.current = false;\n hasScriptsRef.current = false;\n setIsGeneratingStyles(false);\n setIsGeneratingScripts(false);\n\n if (mode === \"blackboard\") {\n appendedStylesRef.current.forEach((node) => node.remove());\n appendedStylesRef.current = [];\n appendedScriptsRef.current.forEach((node) => node.remove());\n appendedScriptsRef.current = [];\n\n if (!runtimeRef.current) {\n runtimeRef.current = new BlackboardRuntime(container);\n }\n\n runtimeRef.current.update(html);\n const hasRendered = runtimeRef.current.hasRenderedContent();\n hasRenderedContentRef.current = hasRendered;\n setIsWaitingFirstDiv(!hasRendered);\n return;\n }\n\n if (runtimeRef.current) {\n runtimeRef.current.reset();\n runtimeRef.current = null;\n }\n\n const doc = container.ownerDocument;\n const body = doc?.body;\n if (!body) return;\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 setIsWaitingFirstDiv(!hasRenderedBefore);\n container.innerHTML = \"\";\n const wrapper = document.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\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 setIsWaitingFirstDiv(!hasFirstElement && !hasRenderedBefore);\n if (hasFirstElement) {\n hasRenderedContentRef.current = true;\n }\n\n const contentNodes = Array.from(wrapper.childNodes);\n container.append(...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 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, mode, resetToken]);\n\n useEffect(\n () => () => {\n clearTimer(styleTimerRef);\n clearTimer(scriptTimerRef);\n runtimeRef.current = null;\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\n return (\n <div\n ref={wrapperRef}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className=\"sandbox-wrapper\"\n style={{\n position: \"relative\",\n width: \"100%\",\n height: isBlackboard ? \"100dvh\" : undefined,\n display: \"flex\",\n flexDirection: \"column\",\n // if use center, too long iframe wont see header\n justifyContent: \"space-around\",\n }}\n aria-busy={!!overlayMessage}\n >\n <div\n ref={containerRef}\n className=\"sandbox-container\"\n style={{\n pointerEvents: overlayMessage ? \"none\" : undefined,\n }}\n />\n {overlayMessage && (\n <div\n style={{\n position: \"absolute\",\n inset: 0,\n display: \"flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n background: \"rgba(51, 51, 51, 0.80)\",\n color: \"#ffffff\",\n fontSize: 16,\n fontWeight: 700,\n gap: 10,\n pointerEvents: \"auto\",\n zIndex: 20,\n }}\n >\n <Loader2\n aria-hidden\n size={20}\n style={{ animation: \"sandbox-spin 1s linear infinite\" }}\n />\n {overlayMessage}\n </div>\n )}\n </div>\n );\n};\n\nexport default SandboxApp;\n"],"names":["SandboxApp","html","styleLoadingText","scriptLoadingText","resetToken","mode","hasRootVhHeight","wrapperRef","useRef","containerRef","setIsWaitingFirstDiv","useState","isGeneratingStyles","setIsGeneratingStyles","isGeneratingScripts","setIsGeneratingScripts","appendedStylesRef","appendedScriptsRef","styleStartRef","scriptStartRef","styleTimerRef","scriptTimerRef","hasStylesRef","hasScriptsRef","hasRenderedContentRef","prevResetTokenRef","runtimeRef","MIN_LOADING_MS","clearTimer","timerRef","settleStateWithMinimumDelay","setter","startRef","onDone","elapsed","delay","useEffect","doc","styleId","styleEl","container","node","BlackboardRuntime","hasRendered","body","hasRenderedBefore","wrapper","openScriptCount","closeScriptCount","shouldExecuteScripts","resourceQueue","cloned","attr","replacement","hasStyles","hasScripts","hasFirstElement","cont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AAA,kBACX,MAAM;AAAA,kBACN,OAAO,EAAE,WAAW,kCAAA;AAAA,gBAAkC;AAAA,cAAA;AAAA,cAEvDJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAAA;AAAA,EAAA;AAIR;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.cjs.js"),p=require("./diff-parser.cjs.js"),u=/^---\s+a\/(\d+)/,g=/^\+\+\+\s+b\/(\d+)/;class E{constructor(e){this.renderedHtmlCount=0,this.renderedDiffCount=0,this.host=e,this.doc=e.ownerDocument,this.stage=this.ensureStageContainer()}ensureStageContainer(){let e=this.host.querySelector("#ppt-container");return e||(e=this.doc.createElement("div"),e.id="ppt-container",e.style.width="100%",e.style.minHeight="100dvh",e.style.position="relative",this.host.appendChild(e)),e}reset(){this.renderedHtmlCount=0,this.renderedDiffCount=0,this.stage.innerHTML=""}hasRenderedContent(){return this.stage.childElementCount>0}update(e){const t=p.parseBlackboardStream(e);if(t.hasUnclosedDiffBlock)return;const n=t.htmlBlocks.length<this.renderedHtmlCount&&!t.isPureDiffPayload,i=t.diffBlocks.length<this.renderedDiffCount;(n||i)&&this.reset();for(let r=this.renderedHtmlCount;r<t.htmlBlocks.length;r+=1)this.appendHtml(t.htmlBlocks[r]);this.renderedHtmlCount=t.htmlBlocks.length;for(let r=this.renderedDiffCount;r<t.diffBlocks.length;r+=1)this.applyDiff(t.diffBlocks[r]);this.renderedDiffCount=t.diffBlocks.length}appendHtml(e){const n=new DOMParser().parseFromString(e,"text/html");Array.from(n.body.childNodes).forEach(s=>{if(s.nodeType===Node.ELEMENT_NODE){const r=s;if(r.tagName==="SCRIPT"){const a=this.doc.createElement("script");a.textContent=r.textContent,Array.from(r.attributes).forEach(o=>{a.setAttribute(o.name,o.value)}),this.stage.appendChild(a);return}if(r.tagName==="STYLE"){const a=this.doc.createElement("style");a.textContent=r.textContent,Array.from(r.attributes).forEach(o=>{a.setAttribute(o.name,o.value)}),this.stage.appendChild(a);return}this.stage.children.length>0&&(this.stage.innerHTML=""),this.stage.appendChild(this.doc.importNode(r,!0));return}if(s.nodeType===Node.TEXT_NODE&&s.textContent?.trim()){this.stage.children.length>0&&(this.stage.innerHTML="");const r=this.doc.createElement("div");r.textContent=s.textContent,this.stage.appendChild(r)}})}parseUnifiedDiff(e){const t=e.split(`
|
|
2
|
+
`),n=t[0]?.match(u);if(!n)throw new Error('Invalid diff format: missing "--- a/index"');const i=Number.parseInt(n[1],10),s=t[1]?.match(g);if(!s||Number.parseInt(s[1],10)!==i)throw new Error("Invalid diff format: mismatched target index");return{targetIndex:i,patchText:e}}normalizeHTML(e){return e.split(`
|
|
3
|
+
`).map(t=>t.trim()).filter(Boolean).join(`
|
|
4
|
+
`)}normalizePatch(e){const t=JSON.parse(JSON.stringify(e));return t.hunks?.forEach(n=>{n.lines&&(n.lines=n.lines.map(i=>{if(!i)return i;const s=i[0];if(s===" "||s==="+"||s==="-"){const r=i.slice(1).trim();return r?`${s}${r}`:s}return i}))}),t}rehydrateScripts(e){e.querySelectorAll("script").forEach(t=>{const n=this.doc.createElement("script");n.textContent=t.textContent,Array.from(t.attributes).forEach(i=>{n.setAttribute(i.name,i.value)}),t.replaceWith(n)})}applyDiff(e){try{const{targetIndex:t,patchText:n}=this.parseUnifiedDiff(e),i=Array.from(this.stage.children);if(t<0||t>=i.length){console.warn(`[BlackboardRuntime] Diff target index ${t} out of range (0-${i.length-1})`);return}const s=i[t],r=s.outerHTML,a=h.parsePatch(n);if(!a.length){console.warn("[BlackboardRuntime] No valid patches found in diff");return}const o=a[0];let c=h.applyPatch(r,o);if(c===!1){const f=this.normalizeHTML(r),m=this.normalizePatch(o);c=h.applyPatch(f,m)}if(c===!1){console.warn("[BlackboardRuntime] Failed to apply diff patch");return}const d=this.doc.createElement("div");d.innerHTML=c;const l=d.firstElementChild;if(!l)return;this.rehydrateScripts(l),s.replaceWith(l)}catch(t){const n=t instanceof Error?t.message:"Unknown error while applying diff";console.warn("[BlackboardRuntime] Diff apply error:",n)}}}exports.BlackboardRuntime=E;
|
|
5
|
+
//# sourceMappingURL=blackboard-runtime.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blackboard-runtime.cjs.js","sources":["../../../../src/components/ContentRender/blackboard/blackboard-runtime.ts"],"sourcesContent":["import { applyPatch, parsePatch } from \"diff\";\nimport { parseBlackboardStream } from \"./diff-parser\";\n\ninterface ParsedUnifiedDiff {\n targetIndex: number;\n patchText: string;\n}\n\nconst DIFF_TARGET_PATTERN = /^---\\s+a\\/(\\d+)/;\nconst DIFF_NEW_TARGET_PATTERN = /^\\+\\+\\+\\s+b\\/(\\d+)/;\n\nexport class BlackboardRuntime {\n private readonly host: HTMLElement;\n private readonly doc: Document;\n private readonly stage: HTMLDivElement;\n private renderedHtmlCount = 0;\n private renderedDiffCount = 0;\n\n constructor(host: HTMLElement) {\n this.host = host;\n this.doc = host.ownerDocument;\n this.stage = this.ensureStageContainer();\n }\n\n private ensureStageContainer() {\n let stage = this.host.querySelector<HTMLDivElement>(\"#ppt-container\");\n if (!stage) {\n stage = this.doc.createElement(\"div\");\n stage.id = \"ppt-container\";\n stage.style.width = \"100%\";\n stage.style.minHeight = \"100dvh\";\n stage.style.position = \"relative\";\n this.host.appendChild(stage);\n }\n return stage;\n }\n\n reset() {\n this.renderedHtmlCount = 0;\n this.renderedDiffCount = 0;\n this.stage.innerHTML = \"\";\n }\n\n hasRenderedContent() {\n return this.stage.childElementCount > 0;\n }\n\n update(source: string) {\n const parsed = parseBlackboardStream(source);\n\n if (parsed.hasUnclosedDiffBlock) {\n return;\n }\n\n const htmlShrink =\n parsed.htmlBlocks.length < this.renderedHtmlCount &&\n !parsed.isPureDiffPayload;\n const diffShrink = parsed.diffBlocks.length < this.renderedDiffCount;\n const hasShrink = htmlShrink || diffShrink;\n\n if (hasShrink) {\n this.reset();\n }\n\n for (\n let index = this.renderedHtmlCount;\n index < parsed.htmlBlocks.length;\n index += 1\n ) {\n this.appendHtml(parsed.htmlBlocks[index]);\n }\n\n this.renderedHtmlCount = parsed.htmlBlocks.length;\n\n for (\n let index = this.renderedDiffCount;\n index < parsed.diffBlocks.length;\n index += 1\n ) {\n this.applyDiff(parsed.diffBlocks[index]);\n }\n\n this.renderedDiffCount = parsed.diffBlocks.length;\n }\n\n private appendHtml(html: string) {\n const parser = new DOMParser();\n const parsedDoc = parser.parseFromString(html, \"text/html\");\n const nodes = Array.from(parsedDoc.body.childNodes);\n\n nodes.forEach((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = node as HTMLElement;\n\n if (element.tagName === \"SCRIPT\") {\n const script = this.doc.createElement(\"script\");\n script.textContent = element.textContent;\n Array.from(element.attributes).forEach((attr) => {\n script.setAttribute(attr.name, attr.value);\n });\n this.stage.appendChild(script);\n return;\n }\n\n if (element.tagName === \"STYLE\") {\n const style = this.doc.createElement(\"style\");\n style.textContent = element.textContent;\n Array.from(element.attributes).forEach((attr) => {\n style.setAttribute(attr.name, attr.value);\n });\n this.stage.appendChild(style);\n return;\n }\n\n if (this.stage.children.length > 0) {\n this.stage.innerHTML = \"\";\n }\n\n this.stage.appendChild(this.doc.importNode(element, true));\n return;\n }\n\n if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {\n if (this.stage.children.length > 0) {\n this.stage.innerHTML = \"\";\n }\n const textDiv = this.doc.createElement(\"div\");\n textDiv.textContent = node.textContent;\n this.stage.appendChild(textDiv);\n }\n });\n }\n\n private parseUnifiedDiff(diffContent: string): ParsedUnifiedDiff {\n const lines = diffContent.split(\"\\n\");\n const currentMatch = lines[0]?.match(DIFF_TARGET_PATTERN);\n if (!currentMatch) {\n throw new Error('Invalid diff format: missing \"--- a/index\"');\n }\n\n const targetIndex = Number.parseInt(currentMatch[1], 10);\n const newMatch = lines[1]?.match(DIFF_NEW_TARGET_PATTERN);\n if (!newMatch || Number.parseInt(newMatch[1], 10) !== targetIndex) {\n throw new Error(\"Invalid diff format: mismatched target index\");\n }\n\n return { targetIndex, patchText: diffContent };\n }\n\n private normalizeHTML(html: string) {\n return html\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter(Boolean)\n .join(\"\\n\");\n }\n\n private normalizePatch<T extends { hunks?: Array<{ lines?: string[] }> }>(\n patch: T\n ): T {\n const clonedPatch = JSON.parse(JSON.stringify(patch)) as T;\n clonedPatch.hunks?.forEach((hunk) => {\n if (!hunk.lines) {\n return;\n }\n\n hunk.lines = hunk.lines.map((line) => {\n if (!line) {\n return line;\n }\n\n const marker = line[0];\n if (marker === \" \" || marker === \"+\" || marker === \"-\") {\n const normalized = line.slice(1).trim();\n return normalized ? `${marker}${normalized}` : marker;\n }\n\n return line;\n });\n });\n return clonedPatch;\n }\n\n private rehydrateScripts(element: Element) {\n element.querySelectorAll(\"script\").forEach((oldScript) => {\n const newScript = this.doc.createElement(\"script\");\n newScript.textContent = oldScript.textContent;\n Array.from(oldScript.attributes).forEach((attr) => {\n newScript.setAttribute(attr.name, attr.value);\n });\n oldScript.replaceWith(newScript);\n });\n }\n\n private applyDiff(diffContent: string) {\n try {\n const { targetIndex, patchText } = this.parseUnifiedDiff(diffContent);\n const children = Array.from(this.stage.children);\n\n if (targetIndex < 0 || targetIndex >= children.length) {\n console.warn(\n `[BlackboardRuntime] Diff target index ${targetIndex} out of range (0-${children.length - 1})`\n );\n return;\n }\n\n const target = children[targetIndex] as HTMLElement;\n const currentHTML = target.outerHTML;\n const patches = parsePatch(patchText);\n\n if (!patches.length) {\n console.warn(\"[BlackboardRuntime] No valid patches found in diff\");\n return;\n }\n\n const firstPatch = patches[0];\n let result = applyPatch(currentHTML, firstPatch);\n\n if (result === false) {\n const normalizedHTML = this.normalizeHTML(currentHTML);\n const normalizedPatch = this.normalizePatch(firstPatch);\n result = applyPatch(normalizedHTML, normalizedPatch);\n }\n\n if (result === false) {\n console.warn(\"[BlackboardRuntime] Failed to apply diff patch\");\n return;\n }\n\n const temp = this.doc.createElement(\"div\");\n temp.innerHTML = result;\n const nextElement = temp.firstElementChild;\n if (!nextElement) {\n return;\n }\n\n this.rehydrateScripts(nextElement);\n target.replaceWith(nextElement);\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : \"Unknown error while applying diff\";\n console.warn(\"[BlackboardRuntime] Diff apply error:\", message);\n }\n }\n}\n"],"names":["DIFF_TARGET_PATTERN","DIFF_NEW_TARGET_PATTERN","BlackboardRuntime","host","stage","source","parsed","parseBlackboardStream","htmlShrink","diffShrink","index","html","parsedDoc","node","element","script","attr","style","textDiv","diffContent","lines","currentMatch","targetIndex","newMatch","line","patch","clonedPatch","hunk","marker","normalized","oldScript","newScript","patchText","children","target","currentHTML","patches","parsePatch","firstPatch","result","applyPatch","normalizedHTML","normalizedPatch","temp","nextElement","error","message"],"mappings":"mPAQMA,EAAsB,kBACtBC,EAA0B,qBAEzB,MAAMC,CAAkB,CAO7B,YAAYC,EAAmB,CAH/B,KAAQ,kBAAoB,EAC5B,KAAQ,kBAAoB,EAG1B,KAAK,KAAOA,EACZ,KAAK,IAAMA,EAAK,cAChB,KAAK,MAAQ,KAAK,qBAAA,CACpB,CAEQ,sBAAuB,CAC7B,IAAIC,EAAQ,KAAK,KAAK,cAA8B,gBAAgB,EACpE,OAAKA,IACHA,EAAQ,KAAK,IAAI,cAAc,KAAK,EACpCA,EAAM,GAAK,gBACXA,EAAM,MAAM,MAAQ,OACpBA,EAAM,MAAM,UAAY,SACxBA,EAAM,MAAM,SAAW,WACvB,KAAK,KAAK,YAAYA,CAAK,GAEtBA,CACT,CAEA,OAAQ,CACN,KAAK,kBAAoB,EACzB,KAAK,kBAAoB,EACzB,KAAK,MAAM,UAAY,EACzB,CAEA,oBAAqB,CACnB,OAAO,KAAK,MAAM,kBAAoB,CACxC,CAEA,OAAOC,EAAgB,CACrB,MAAMC,EAAS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AcD,EAAK,kBACzB,GAAI,CAACC,EACH,OAGF,KAAK,iBAAiBA,CAAW,EACjCV,EAAO,YAAYU,CAAW,CAChC,OAASC,EAAO,CACd,MAAMC,EACJD,aAAiB,MACbA,EAAM,QACN,oCACN,QAAQ,KAAK,wCAAyCC,CAAO,CAC/D,CACF,CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class BlackboardRuntime {
|
|
2
|
+
private readonly host;
|
|
3
|
+
private readonly doc;
|
|
4
|
+
private readonly stage;
|
|
5
|
+
private renderedHtmlCount;
|
|
6
|
+
private renderedDiffCount;
|
|
7
|
+
constructor(host: HTMLElement);
|
|
8
|
+
private ensureStageContainer;
|
|
9
|
+
reset(): void;
|
|
10
|
+
hasRenderedContent(): boolean;
|
|
11
|
+
update(source: string): void;
|
|
12
|
+
private appendHtml;
|
|
13
|
+
private parseUnifiedDiff;
|
|
14
|
+
private normalizeHTML;
|
|
15
|
+
private normalizePatch;
|
|
16
|
+
private rehydrateScripts;
|
|
17
|
+
private applyDiff;
|
|
18
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { parsePatch as p, applyPatch as d } from "../../../Documents/ai-shifu/markdown-flow-ui/node_modules/.pnpm/diff@5.2.0/node_modules/diff/lib/index.es.js";
|
|
2
|
+
import { parseBlackboardStream as u } from "./diff-parser.es.js";
|
|
3
|
+
const g = /^---\s+a\/(\d+)/, E = /^\+\+\+\s+b\/(\d+)/;
|
|
4
|
+
class x {
|
|
5
|
+
constructor(e) {
|
|
6
|
+
this.renderedHtmlCount = 0, this.renderedDiffCount = 0, this.host = e, this.doc = e.ownerDocument, this.stage = this.ensureStageContainer();
|
|
7
|
+
}
|
|
8
|
+
ensureStageContainer() {
|
|
9
|
+
let e = this.host.querySelector("#ppt-container");
|
|
10
|
+
return e || (e = this.doc.createElement("div"), e.id = "ppt-container", e.style.width = "100%", e.style.minHeight = "100dvh", e.style.position = "relative", this.host.appendChild(e)), e;
|
|
11
|
+
}
|
|
12
|
+
reset() {
|
|
13
|
+
this.renderedHtmlCount = 0, this.renderedDiffCount = 0, this.stage.innerHTML = "";
|
|
14
|
+
}
|
|
15
|
+
hasRenderedContent() {
|
|
16
|
+
return this.stage.childElementCount > 0;
|
|
17
|
+
}
|
|
18
|
+
update(e) {
|
|
19
|
+
const t = u(e);
|
|
20
|
+
if (t.hasUnclosedDiffBlock)
|
|
21
|
+
return;
|
|
22
|
+
const n = t.htmlBlocks.length < this.renderedHtmlCount && !t.isPureDiffPayload, i = t.diffBlocks.length < this.renderedDiffCount;
|
|
23
|
+
(n || i) && this.reset();
|
|
24
|
+
for (let r = this.renderedHtmlCount; r < t.htmlBlocks.length; r += 1)
|
|
25
|
+
this.appendHtml(t.htmlBlocks[r]);
|
|
26
|
+
this.renderedHtmlCount = t.htmlBlocks.length;
|
|
27
|
+
for (let r = this.renderedDiffCount; r < t.diffBlocks.length; r += 1)
|
|
28
|
+
this.applyDiff(t.diffBlocks[r]);
|
|
29
|
+
this.renderedDiffCount = t.diffBlocks.length;
|
|
30
|
+
}
|
|
31
|
+
appendHtml(e) {
|
|
32
|
+
const n = new DOMParser().parseFromString(e, "text/html");
|
|
33
|
+
Array.from(n.body.childNodes).forEach((s) => {
|
|
34
|
+
if (s.nodeType === Node.ELEMENT_NODE) {
|
|
35
|
+
const r = s;
|
|
36
|
+
if (r.tagName === "SCRIPT") {
|
|
37
|
+
const o = this.doc.createElement("script");
|
|
38
|
+
o.textContent = r.textContent, Array.from(r.attributes).forEach((a) => {
|
|
39
|
+
o.setAttribute(a.name, a.value);
|
|
40
|
+
}), this.stage.appendChild(o);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (r.tagName === "STYLE") {
|
|
44
|
+
const o = this.doc.createElement("style");
|
|
45
|
+
o.textContent = r.textContent, Array.from(r.attributes).forEach((a) => {
|
|
46
|
+
o.setAttribute(a.name, a.value);
|
|
47
|
+
}), this.stage.appendChild(o);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.stage.children.length > 0 && (this.stage.innerHTML = ""), this.stage.appendChild(this.doc.importNode(r, !0));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (s.nodeType === Node.TEXT_NODE && s.textContent?.trim()) {
|
|
54
|
+
this.stage.children.length > 0 && (this.stage.innerHTML = "");
|
|
55
|
+
const r = this.doc.createElement("div");
|
|
56
|
+
r.textContent = s.textContent, this.stage.appendChild(r);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
parseUnifiedDiff(e) {
|
|
61
|
+
const t = e.split(`
|
|
62
|
+
`), n = t[0]?.match(g);
|
|
63
|
+
if (!n)
|
|
64
|
+
throw new Error('Invalid diff format: missing "--- a/index"');
|
|
65
|
+
const i = Number.parseInt(n[1], 10), s = t[1]?.match(E);
|
|
66
|
+
if (!s || Number.parseInt(s[1], 10) !== i)
|
|
67
|
+
throw new Error("Invalid diff format: mismatched target index");
|
|
68
|
+
return { targetIndex: i, patchText: e };
|
|
69
|
+
}
|
|
70
|
+
normalizeHTML(e) {
|
|
71
|
+
return e.split(`
|
|
72
|
+
`).map((t) => t.trim()).filter(Boolean).join(`
|
|
73
|
+
`);
|
|
74
|
+
}
|
|
75
|
+
normalizePatch(e) {
|
|
76
|
+
const t = JSON.parse(JSON.stringify(e));
|
|
77
|
+
return t.hunks?.forEach((n) => {
|
|
78
|
+
n.lines && (n.lines = n.lines.map((i) => {
|
|
79
|
+
if (!i)
|
|
80
|
+
return i;
|
|
81
|
+
const s = i[0];
|
|
82
|
+
if (s === " " || s === "+" || s === "-") {
|
|
83
|
+
const r = i.slice(1).trim();
|
|
84
|
+
return r ? `${s}${r}` : s;
|
|
85
|
+
}
|
|
86
|
+
return i;
|
|
87
|
+
}));
|
|
88
|
+
}), t;
|
|
89
|
+
}
|
|
90
|
+
rehydrateScripts(e) {
|
|
91
|
+
e.querySelectorAll("script").forEach((t) => {
|
|
92
|
+
const n = this.doc.createElement("script");
|
|
93
|
+
n.textContent = t.textContent, Array.from(t.attributes).forEach((i) => {
|
|
94
|
+
n.setAttribute(i.name, i.value);
|
|
95
|
+
}), t.replaceWith(n);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
applyDiff(e) {
|
|
99
|
+
try {
|
|
100
|
+
const { targetIndex: t, patchText: n } = this.parseUnifiedDiff(e), i = Array.from(this.stage.children);
|
|
101
|
+
if (t < 0 || t >= i.length) {
|
|
102
|
+
console.warn(
|
|
103
|
+
`[BlackboardRuntime] Diff target index ${t} out of range (0-${i.length - 1})`
|
|
104
|
+
);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const s = i[t], r = s.outerHTML, o = p(n);
|
|
108
|
+
if (!o.length) {
|
|
109
|
+
console.warn("[BlackboardRuntime] No valid patches found in diff");
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const a = o[0];
|
|
113
|
+
let c = d(r, a);
|
|
114
|
+
if (c === !1) {
|
|
115
|
+
const f = this.normalizeHTML(r), m = this.normalizePatch(a);
|
|
116
|
+
c = d(f, m);
|
|
117
|
+
}
|
|
118
|
+
if (c === !1) {
|
|
119
|
+
console.warn("[BlackboardRuntime] Failed to apply diff patch");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const l = this.doc.createElement("div");
|
|
123
|
+
l.innerHTML = c;
|
|
124
|
+
const h = l.firstElementChild;
|
|
125
|
+
if (!h)
|
|
126
|
+
return;
|
|
127
|
+
this.rehydrateScripts(h), s.replaceWith(h);
|
|
128
|
+
} catch (t) {
|
|
129
|
+
const n = t instanceof Error ? t.message : "Unknown error while applying diff";
|
|
130
|
+
console.warn("[BlackboardRuntime] Diff apply error:", n);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
x as BlackboardRuntime
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=blackboard-runtime.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blackboard-runtime.es.js","sources":["../../../../src/components/ContentRender/blackboard/blackboard-runtime.ts"],"sourcesContent":["import { applyPatch, parsePatch } from \"diff\";\nimport { parseBlackboardStream } from \"./diff-parser\";\n\ninterface ParsedUnifiedDiff {\n targetIndex: number;\n patchText: string;\n}\n\nconst DIFF_TARGET_PATTERN = /^---\\s+a\\/(\\d+)/;\nconst DIFF_NEW_TARGET_PATTERN = /^\\+\\+\\+\\s+b\\/(\\d+)/;\n\nexport class BlackboardRuntime {\n private readonly host: HTMLElement;\n private readonly doc: Document;\n private readonly stage: HTMLDivElement;\n private renderedHtmlCount = 0;\n private renderedDiffCount = 0;\n\n constructor(host: HTMLElement) {\n this.host = host;\n this.doc = host.ownerDocument;\n this.stage = this.ensureStageContainer();\n }\n\n private ensureStageContainer() {\n let stage = this.host.querySelector<HTMLDivElement>(\"#ppt-container\");\n if (!stage) {\n stage = this.doc.createElement(\"div\");\n stage.id = \"ppt-container\";\n stage.style.width = \"100%\";\n stage.style.minHeight = \"100dvh\";\n stage.style.position = \"relative\";\n this.host.appendChild(stage);\n }\n return stage;\n }\n\n reset() {\n this.renderedHtmlCount = 0;\n this.renderedDiffCount = 0;\n this.stage.innerHTML = \"\";\n }\n\n hasRenderedContent() {\n return this.stage.childElementCount > 0;\n }\n\n update(source: string) {\n const parsed = parseBlackboardStream(source);\n\n if (parsed.hasUnclosedDiffBlock) {\n return;\n }\n\n const htmlShrink =\n parsed.htmlBlocks.length < this.renderedHtmlCount &&\n !parsed.isPureDiffPayload;\n const diffShrink = parsed.diffBlocks.length < this.renderedDiffCount;\n const hasShrink = htmlShrink || diffShrink;\n\n if (hasShrink) {\n this.reset();\n }\n\n for (\n let index = this.renderedHtmlCount;\n index < parsed.htmlBlocks.length;\n index += 1\n ) {\n this.appendHtml(parsed.htmlBlocks[index]);\n }\n\n this.renderedHtmlCount = parsed.htmlBlocks.length;\n\n for (\n let index = this.renderedDiffCount;\n index < parsed.diffBlocks.length;\n index += 1\n ) {\n this.applyDiff(parsed.diffBlocks[index]);\n }\n\n this.renderedDiffCount = parsed.diffBlocks.length;\n }\n\n private appendHtml(html: string) {\n const parser = new DOMParser();\n const parsedDoc = parser.parseFromString(html, \"text/html\");\n const nodes = Array.from(parsedDoc.body.childNodes);\n\n nodes.forEach((node) => {\n if (node.nodeType === Node.ELEMENT_NODE) {\n const element = node as HTMLElement;\n\n if (element.tagName === \"SCRIPT\") {\n const script = this.doc.createElement(\"script\");\n script.textContent = element.textContent;\n Array.from(element.attributes).forEach((attr) => {\n script.setAttribute(attr.name, attr.value);\n });\n this.stage.appendChild(script);\n return;\n }\n\n if (element.tagName === \"STYLE\") {\n const style = this.doc.createElement(\"style\");\n style.textContent = element.textContent;\n Array.from(element.attributes).forEach((attr) => {\n style.setAttribute(attr.name, attr.value);\n });\n this.stage.appendChild(style);\n return;\n }\n\n if (this.stage.children.length > 0) {\n this.stage.innerHTML = \"\";\n }\n\n this.stage.appendChild(this.doc.importNode(element, true));\n return;\n }\n\n if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {\n if (this.stage.children.length > 0) {\n this.stage.innerHTML = \"\";\n }\n const textDiv = this.doc.createElement(\"div\");\n textDiv.textContent = node.textContent;\n this.stage.appendChild(textDiv);\n }\n });\n }\n\n private parseUnifiedDiff(diffContent: string): ParsedUnifiedDiff {\n const lines = diffContent.split(\"\\n\");\n const currentMatch = lines[0]?.match(DIFF_TARGET_PATTERN);\n if (!currentMatch) {\n throw new Error('Invalid diff format: missing \"--- a/index\"');\n }\n\n const targetIndex = Number.parseInt(currentMatch[1], 10);\n const newMatch = lines[1]?.match(DIFF_NEW_TARGET_PATTERN);\n if (!newMatch || Number.parseInt(newMatch[1], 10) !== targetIndex) {\n throw new Error(\"Invalid diff format: mismatched target index\");\n }\n\n return { targetIndex, patchText: diffContent };\n }\n\n private normalizeHTML(html: string) {\n return html\n .split(\"\\n\")\n .map((line) => line.trim())\n .filter(Boolean)\n .join(\"\\n\");\n }\n\n private normalizePatch<T extends { hunks?: Array<{ lines?: string[] }> }>(\n patch: T\n ): T {\n const clonedPatch = JSON.parse(JSON.stringify(patch)) as T;\n clonedPatch.hunks?.forEach((hunk) => {\n if (!hunk.lines) {\n return;\n }\n\n hunk.lines = hunk.lines.map((line) => {\n if (!line) {\n return line;\n }\n\n const marker = line[0];\n if (marker === \" \" || marker === \"+\" || marker === \"-\") {\n const normalized = line.slice(1).trim();\n return normalized ? `${marker}${normalized}` : marker;\n }\n\n return line;\n });\n });\n return clonedPatch;\n }\n\n private rehydrateScripts(element: Element) {\n element.querySelectorAll(\"script\").forEach((oldScript) => {\n const newScript = this.doc.createElement(\"script\");\n newScript.textContent = oldScript.textContent;\n Array.from(oldScript.attributes).forEach((attr) => {\n newScript.setAttribute(attr.name, attr.value);\n });\n oldScript.replaceWith(newScript);\n });\n }\n\n private applyDiff(diffContent: string) {\n try {\n const { targetIndex, patchText } = this.parseUnifiedDiff(diffContent);\n const children = Array.from(this.stage.children);\n\n if (targetIndex < 0 || targetIndex >= children.length) {\n console.warn(\n `[BlackboardRuntime] Diff target index ${targetIndex} out of range (0-${children.length - 1})`\n );\n return;\n }\n\n const target = children[targetIndex] as HTMLElement;\n const currentHTML = target.outerHTML;\n const patches = parsePatch(patchText);\n\n if (!patches.length) {\n console.warn(\"[BlackboardRuntime] No valid patches found in diff\");\n return;\n }\n\n const firstPatch = patches[0];\n let result = applyPatch(currentHTML, firstPatch);\n\n if (result === false) {\n const normalizedHTML = this.normalizeHTML(currentHTML);\n const normalizedPatch = this.normalizePatch(firstPatch);\n result = applyPatch(normalizedHTML, normalizedPatch);\n }\n\n if (result === false) {\n console.warn(\"[BlackboardRuntime] Failed to apply diff patch\");\n return;\n }\n\n const temp = this.doc.createElement(\"div\");\n temp.innerHTML = result;\n const nextElement = temp.firstElementChild;\n if (!nextElement) {\n return;\n }\n\n this.rehydrateScripts(nextElement);\n target.replaceWith(nextElement);\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : \"Unknown error while applying diff\";\n console.warn(\"[BlackboardRuntime] Diff apply error:\", message);\n }\n }\n}\n"],"names":["DIFF_TARGET_PATTERN","DIFF_NEW_TARGET_PATTERN","BlackboardRuntime","host","stage","source","parsed","parseBlackboardStream","htmlShrink","diffShrink","index","html","parsedDoc","node","element","script","attr","style","textDiv","diffContent","lines","currentMatch","targetIndex","newMatch","line","patch","clonedPatch","hunk","marker","normalized","oldScript","newScript","patchText","children","target","currentHTML","patches","parsePatch","firstPatch","result","applyPatch","normalizedHTML","normalizedPatch","temp","nextElement","error","message"],"mappings":";;AAQA,MAAMA,IAAsB,mBACtBC,IAA0B;AAEzB,MAAMC,EAAkB;AAAA,EAO7B,YAAYC,GAAmB;AAH/B,SAAQ,oBAAoB,GAC5B,KAAQ,oBAAoB,GAG1B,KAAK,OAAOA,GACZ,KAAK,MAAMA,EAAK,eAChB,KAAK,QAAQ,KAAK,qBAAA;AAAA,EACpB;AAAA,EAEQ,uBAAuB;AAC7B,QAAIC,IAAQ,KAAK,KAAK,cAA8B,gBAAgB;AACpE,WAAKA,MACHA,IAAQ,KAAK,IAAI,cAAc,KAAK,GACpCA,EAAM,KAAK,iBACXA,EAAM,MAAM,QAAQ,QACpBA,EAAM,MAAM,YAAY,UACxBA,EAAM,MAAM,WAAW,YACvB,KAAK,KAAK,YAAYA,CAAK,IAEtBA;AAAA,EACT;AAAA,EAEA,QAAQ;AACN,SAAK,oBAAoB,GACzB,KAAK,oBAAoB,GACzB,KAAK,MAAM,YAAY;AAAA,EACzB;AAAA,EAEA,qBAAqB;AACnB,WAAO,KAAK,MAAM,oBAAoB;AAAA,EACxC;AAAA,EAEA,OAAOC,GAAgB;AACrB,UAAMC,IAASC,EAAsBF,CAAM;AAE3C,QAAIC,EAAO;AACT;AAGF,UAAME,IACJF,EAAO,WAAW,SAAS,KAAK,qBAChC,CAACA,EAAO,mBACJG,IAAaH,EAAO,WAAW,SAAS,KAAK;AAGnD,KAFkBE,KAAcC,MAG9B,KAAK,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Q,KAAK,gDAAgD;AAC7D;AAAA,MACF;AAEA,YAAMI,IAAO,KAAK,IAAI,cAAc,KAAK;AACzC,MAAAA,EAAK,YAAYJ;AACjB,YAAMK,IAAcD,EAAK;AACzB,UAAI,CAACC;AACH;AAGF,WAAK,iBAAiBA,CAAW,GACjCV,EAAO,YAAYU,CAAW;AAAA,IAChC,SAASC,GAAO;AACd,YAAMC,IACJD,aAAiB,QACbA,EAAM,UACN;AACN,cAAQ,KAAK,yCAAyCC,CAAO;AAAA,IAC/D;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=["div","style","script","h1","h2","h3","h4","h5","h6","p","svg","section","article","figure","figcaption","aside","header","footer","nav","main","ul","ol","li","table","thead","tbody","tfoot","tr","th","td","caption","canvas","form","fieldset","blockquote","pre"],g=/!\+\+\+\s*([\s\S]+?)\s*!\+\+\+/g,m=/!\+\+\+/g,u=/!\+\+\+[\s\S]*?!\+\+\+/g,B=e=>{const i=[];let s;for(g.lastIndex=0;(s=g.exec(e))!==null;)i.push({content:s[1],fullMatch:s[0]});return i},x=(e,i,s)=>{const f=`<${s}`,o=`</${s}>`,a=e.indexOf(">",i);if(a===-1)return-1;let t=1,n=a+1;for(;n<e.length&&t>0;){const r=e.indexOf(f,n),c=e.indexOf(o,n);if(c===-1)return-1;if(r!==-1&&r<c){t+=1;const l=e.indexOf(">",r);n=l===-1?r+f.length:l+1;continue}if(t-=1,t===0)return c+o.length;n=c+o.length}return-1},b=e=>{const i=[],s=[];let f=-1,o=0;for(;o<e.length;){let t=-1,n=null,r=!1;if(T.forEach(l=>{const h=`<${l}`,k=`</${l}>`,d=e.indexOf(h,o),p=e.indexOf(k,o);d!==-1&&(t===-1||d<t)&&(t=d,n=l,r=!0),p!==-1&&(t===-1||p<t)&&(t=p,n=l,r=!1)}),t===-1||!n)break;if(r){if(s.length===0){const h=x(e,t,n);if(h!==-1){i.push(e.substring(t,h)),o=h;continue}f===-1&&(f=t)}s.push({tagName:n,pos:t});const l=e.indexOf(">",t);o=l!==-1?l+1:t+n.length+1;continue}const c=s[s.length-1];c&&c.tagName===n&&s.pop(),o=t+n.length+3}const a=f===-1?"":e.substring(f);return{blocks:i,pendingHTML:a}},E=e=>{if(!e)return{htmlBlocks:[],diffBlocks:[],pendingHTML:"",hasUnclosedDiffBlock:!1,isPureDiffPayload:!1};const i=e.trim(),f=!!i.match(u)?.length&&i.replace(u,"").trim().length===0,o=B(e);let a=e;if(o.forEach((c,l)=>{a=a.replace(c.fullMatch,`__EXTRACTED_DIFF_${l}__`)}),(a.match(m)||[]).length%2!==0)return{htmlBlocks:[],diffBlocks:[],pendingHTML:"",hasUnclosedDiffBlock:!0,isPureDiffPayload:f};const{blocks:n,pendingHTML:r}=b(a);return{htmlBlocks:n,diffBlocks:o.map(c=>c.content),pendingHTML:r,hasUnclosedDiffBlock:!1,isPureDiffPayload:f}};exports.parseBlackboardStream=E;
|
|
2
|
+
//# sourceMappingURL=diff-parser.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-parser.cjs.js","sources":["../../../../src/components/ContentRender/blackboard/diff-parser.ts"],"sourcesContent":["interface ExtractedDiffBlock {\n content: string;\n fullMatch: string;\n}\n\nexport interface BlackboardParseResult {\n htmlBlocks: string[];\n diffBlocks: string[];\n pendingHTML: string;\n hasUnclosedDiffBlock: boolean;\n isPureDiffPayload: boolean;\n}\n\nconst TARGET_TAGS = [\n \"div\",\n \"style\",\n \"script\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"p\",\n \"svg\",\n \"section\",\n \"article\",\n \"figure\",\n \"figcaption\",\n \"aside\",\n \"header\",\n \"footer\",\n \"nav\",\n \"main\",\n \"ul\",\n \"ol\",\n \"li\",\n \"table\",\n \"thead\",\n \"tbody\",\n \"tfoot\",\n \"tr\",\n \"th\",\n \"td\",\n \"caption\",\n \"canvas\",\n \"form\",\n \"fieldset\",\n \"blockquote\",\n \"pre\",\n];\n\nconst DIFF_BLOCK_PATTERN = /!\\+\\+\\+\\s*([\\s\\S]+?)\\s*!\\+\\+\\+/g;\nconst DIFF_MARKER_PATTERN = /!\\+\\+\\+/g;\nconst PURE_DIFF_BLOCK_PATTERN = /!\\+\\+\\+[\\s\\S]*?!\\+\\+\\+/g;\n\nconst extractDiffBlocks = (content: string): ExtractedDiffBlock[] => {\n const blocks: ExtractedDiffBlock[] = [];\n let match: RegExpExecArray | null;\n DIFF_BLOCK_PATTERN.lastIndex = 0;\n\n while ((match = DIFF_BLOCK_PATTERN.exec(content)) !== null) {\n blocks.push({\n content: match[1],\n fullMatch: match[0],\n });\n }\n\n return blocks;\n};\n\nconst findMatchingCloseTag = (\n content: string,\n startPos: number,\n tagName: string\n) => {\n const openTag = `<${tagName}`;\n const closeTag = `</${tagName}>`;\n const openTagEnd = content.indexOf(\">\", startPos);\n\n if (openTagEnd === -1) {\n return -1;\n }\n\n let depth = 1;\n let searchPos = openTagEnd + 1;\n\n while (searchPos < content.length && depth > 0) {\n const nextOpen = content.indexOf(openTag, searchPos);\n const nextClose = content.indexOf(closeTag, searchPos);\n\n if (nextClose === -1) {\n return -1;\n }\n\n if (nextOpen !== -1 && nextOpen < nextClose) {\n depth += 1;\n const openEnd = content.indexOf(\">\", nextOpen);\n searchPos = openEnd === -1 ? nextOpen + openTag.length : openEnd + 1;\n continue;\n }\n\n depth -= 1;\n if (depth === 0) {\n return nextClose + closeTag.length;\n }\n searchPos = nextClose + closeTag.length;\n }\n\n return -1;\n};\n\nconst extractAllCompleteBlocks = (content: string) => {\n const blocks: string[] = [];\n const unmatchedOpens: Array<{ tagName: string; pos: number }> = [];\n let pendingStart = -1;\n let cursor = 0;\n\n while (cursor < content.length) {\n let nextTagPos = -1;\n let nextTagName: string | null = null;\n let nextIsOpen = false;\n\n TARGET_TAGS.forEach((tagName) => {\n const openTag = `<${tagName}`;\n const closeTag = `</${tagName}>`;\n const openPos = content.indexOf(openTag, cursor);\n const closePos = content.indexOf(closeTag, cursor);\n\n if (openPos !== -1 && (nextTagPos === -1 || openPos < nextTagPos)) {\n nextTagPos = openPos;\n nextTagName = tagName;\n nextIsOpen = true;\n }\n\n if (closePos !== -1 && (nextTagPos === -1 || closePos < nextTagPos)) {\n nextTagPos = closePos;\n nextTagName = tagName;\n nextIsOpen = false;\n }\n });\n\n if (nextTagPos === -1 || !nextTagName) {\n break;\n }\n\n if (nextIsOpen) {\n if (unmatchedOpens.length === 0) {\n const blockEnd = findMatchingCloseTag(content, nextTagPos, nextTagName);\n if (blockEnd !== -1) {\n blocks.push(content.substring(nextTagPos, blockEnd));\n cursor = blockEnd;\n continue;\n }\n if (pendingStart === -1) {\n pendingStart = nextTagPos;\n }\n }\n\n unmatchedOpens.push({ tagName: nextTagName, pos: nextTagPos });\n const tagEnd = content.indexOf(\">\", nextTagPos);\n cursor = tagEnd !== -1 ? tagEnd + 1 : nextTagPos + nextTagName.length + 1;\n continue;\n }\n\n const top = unmatchedOpens[unmatchedOpens.length - 1];\n if (top && top.tagName === nextTagName) {\n unmatchedOpens.pop();\n }\n cursor = nextTagPos + nextTagName.length + 3;\n }\n\n const pendingHTML =\n pendingStart === -1 ? \"\" : content.substring(pendingStart);\n return { blocks, pendingHTML };\n};\n\nexport const parseBlackboardStream = (\n source: string\n): BlackboardParseResult => {\n if (!source) {\n return {\n htmlBlocks: [],\n diffBlocks: [],\n pendingHTML: \"\",\n hasUnclosedDiffBlock: false,\n isPureDiffPayload: false,\n };\n }\n\n const normalizedSource = source.trim();\n const pureDiffBlocks = normalizedSource.match(PURE_DIFF_BLOCK_PATTERN);\n const isPureDiffPayload =\n !!pureDiffBlocks?.length &&\n normalizedSource.replace(PURE_DIFF_BLOCK_PATTERN, \"\").trim().length === 0;\n\n const diffBlocks = extractDiffBlocks(source);\n let processedContent = source;\n\n diffBlocks.forEach((diffBlock, index) => {\n processedContent = processedContent.replace(\n diffBlock.fullMatch,\n `__EXTRACTED_DIFF_${index}__`\n );\n });\n\n const markerCount = (processedContent.match(DIFF_MARKER_PATTERN) || [])\n .length;\n if (markerCount % 2 !== 0) {\n return {\n htmlBlocks: [],\n diffBlocks: [],\n pendingHTML: \"\",\n hasUnclosedDiffBlock: true,\n isPureDiffPayload,\n };\n }\n\n const { blocks, pendingHTML } = extractAllCompleteBlocks(processedContent);\n\n return {\n htmlBlocks: blocks,\n diffBlocks: diffBlocks.map((block) => block.content),\n pendingHTML,\n hasUnclosedDiffBlock: false,\n isPureDiffPayload,\n };\n};\n"],"names":["TARGET_TAGS","DIFF_BLOCK_PATTERN","DIFF_MARKER_PATTERN","PURE_DIFF_BLOCK_PATTERN","extractDiffBlocks","content","blocks","match","findMatchingCloseTag","startPos","tagName","openTag","closeTag","openTagEnd","depth","searchPos","nextOpen","nextClose","openEnd","extractAllCompleteBlocks","unmatchedOpens","pendingStart","cursor","nextTagPos","nextTagName","nextIsOpen","openPos","closePos","blockEnd","tagEnd","top","pendingHTML","parseBlackboardStream","source","normalizedSource","isPureDiffPayload","diffBlocks","processedContent","diffBlock","index","block"],"mappings":"gFAaA,MAAMA,EAAc,CAClB,MACA,QACA,SACA,KACA,KACA,KACA,KACA,KACA,KACA,IACA,MACA,UACA,UACA,SACA,aACA,QACA,SACA,SACA,MACA,OACA,KACA,KACA,KACA,QACA,QACA,QACA,QACA,KACA,KACA,KACA,UACA,SACA,OACA,WACA,aACA,KACF,EAEMC,EAAqB,kCACrBC,EAAsB,WACtBC,EAA0B,0BAE1BC,EAAqBC,GAA0C,CACnE,MAAMC,EAA+B,CAAA,EACrC,IAAIC,EAGJ,IAFAN,EAAmB,UAAY,GAEvBM,EAAQN,EAAmB,KAAKI,CAAO,KAAO,MACpDC,EAAO,KAAK,CACV,QAASC,EAAM,CAAC,EAChB,UAAWA,EAAM,CAAC,CAAA,CACnB,EAGH,OAAOD,CACT,EAEME,EAAuB,CAC3BH,EACAI,EACAC,IACG,CACH,M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C,CAAA,EAIJ,KAAM,CAAE,OAAA7B,EAAQ,YAAAyB,GAAgBZ,EAAyBkB,CAAgB,EAEzE,MAAO,CACL,WAAY/B,EACZ,WAAY8B,EAAW,IAAKI,GAAUA,EAAM,OAAO,EACnD,YAAAT,EACA,qBAAsB,GACtB,kBAAAI,CAAA,CAEJ"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface BlackboardParseResult {
|
|
2
|
+
htmlBlocks: string[];
|
|
3
|
+
diffBlocks: string[];
|
|
4
|
+
pendingHTML: string;
|
|
5
|
+
hasUnclosedDiffBlock: boolean;
|
|
6
|
+
isPureDiffPayload: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const parseBlackboardStream: (source: string) => BlackboardParseResult;
|