@monkeyplus/flow 6.0.43 → 6.0.45
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/package.json +1 -1
- package/src/main.mjs +33 -1
package/package.json
CHANGED
package/src/main.mjs
CHANGED
|
@@ -32,7 +32,39 @@ if (typeof window !== "undefined") {
|
|
|
32
32
|
window.addEventListener("message", async (event) => {
|
|
33
33
|
if (event.data && event.data.type === "flow:preview:morph" && event.data.html) {
|
|
34
34
|
const { Idiomorph } = await import("idiomorph/dist/idiomorph.esm.js");
|
|
35
|
-
|
|
35
|
+
const htmlContent = event.data.html.replace(/^<!DOCTYPE\s+[^>]*>/i, "").trim();
|
|
36
|
+
const parser = new DOMParser();
|
|
37
|
+
const newDoc = parser.parseFromString(htmlContent, "text/html");
|
|
38
|
+
const observer = new MutationObserver((mutations) => {
|
|
39
|
+
for (const m of mutations) {
|
|
40
|
+
let target = m.target;
|
|
41
|
+
if (m.type === "characterData") {
|
|
42
|
+
target = m.target.parentElement;
|
|
43
|
+
} else if (m.type === "childList" && m.addedNodes.length > 0) {
|
|
44
|
+
target = m.addedNodes[0].nodeType === 3 ? m.addedNodes[0].parentElement : m.addedNodes[0];
|
|
45
|
+
}
|
|
46
|
+
if (target && target.nodeType === 1 && target.tagName !== "SCRIPT" && target.tagName !== "STYLE") {
|
|
47
|
+
const rect = target.getBoundingClientRect();
|
|
48
|
+
const inView = rect.top >= 0 && rect.bottom <= window.innerHeight;
|
|
49
|
+
if (!inView && target.scrollIntoView) {
|
|
50
|
+
target.scrollIntoView({ behavior: "smooth", block: "nearest" });
|
|
51
|
+
}
|
|
52
|
+
const oldOutline = target.style.outline;
|
|
53
|
+
const oldTransition = target.style.transition;
|
|
54
|
+
target.style.transition = "outline 0.3s ease-out";
|
|
55
|
+
target.style.outline = "2px solid rgba(59, 130, 246, 0.5)";
|
|
56
|
+
target.style.outlineOffset = "2px";
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
target.style.outline = oldOutline;
|
|
59
|
+
target.style.transition = oldTransition;
|
|
60
|
+
}, 800);
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
observer.observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true });
|
|
66
|
+
Idiomorph.morph(document.body, newDoc.body);
|
|
67
|
+
setTimeout(() => observer.disconnect(), 10);
|
|
36
68
|
}
|
|
37
69
|
});
|
|
38
70
|
}
|