mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(core): words in a scene the preview mounts later keep their spaces (#7342)
* fix(core): words in a scene the preview mounts later keep their spaces * fix(core): a scene laid out for its scripts ignores clicks until it shows
This commit is contained in:
@@ -1961,6 +1961,27 @@ describe("the preview's scene window", () => {
|
||||
expect(sceneHost("s2").getAttribute("style")).not.toContain("display: none");
|
||||
});
|
||||
|
||||
it("lays out a scene the visibility pass hid by display, unseen, while its script builds its timeline", async () => {
|
||||
const seen =
|
||||
`var h = document.querySelector('[data-hf-scene="s2"]:not(style):not(script)');` +
|
||||
`document.body.setAttribute("data-s2-seen", [getComputedStyle(h).display, h.style.opacity, h.hasAttribute("inert")].join(" "));`;
|
||||
const leaf: Scene = {
|
||||
...S2,
|
||||
body: "<p>two</p>",
|
||||
extraAttrs: ' style="position: static"',
|
||||
script: seen,
|
||||
};
|
||||
bootWindowed([S0, S1, leaf], trackingRoot().root);
|
||||
await tick();
|
||||
// Paused in the middle scene, the last one mounts as next, hidden until it plays.
|
||||
await seekAndSettle(2.5);
|
||||
for (let i = 0; i < 5; i++) await tick();
|
||||
expect(document.body.getAttribute("data-s2-seen")).toBe("block 0 true");
|
||||
expect(sceneHost("s2").getAttribute("style")).toContain("display: none");
|
||||
expect(sceneHost("s2").getAttribute("style")).not.toContain("opacity");
|
||||
expect(sceneHost("s2").hasAttribute("inert")).toBe(false);
|
||||
});
|
||||
|
||||
it("mounts a scene Studio holds for editing and keeps it until Studio lets go", async () => {
|
||||
bootWindowed([S0, S1, S2], trackingRoot().root);
|
||||
await tick();
|
||||
|
||||
@@ -4323,9 +4323,48 @@ export function initSandboxRuntimeModular(): void {
|
||||
}
|
||||
}
|
||||
};
|
||||
// GSAP reads the transform of an element it cannot lay out by moving it out and back before its next
|
||||
// element, past the text between; a host the visibility pass hid by display is laid out, unseen and inert, meanwhile.
|
||||
const layOutHiddenHosts = (hosts: Element[]): (() => void) => {
|
||||
const hidden = hosts.filter((host): host is StylableElement =>
|
||||
displayBeforeHide.has(host as StylableElement),
|
||||
);
|
||||
const opacities = hidden.map((host) => {
|
||||
const before = displayBeforeHide.get(host)!;
|
||||
if (before.value) host.style.setProperty("display", before.value, before.priority);
|
||||
else host.style.removeProperty("display");
|
||||
const opacity = {
|
||||
value: host.style.getPropertyValue("opacity"),
|
||||
priority: host.style.getPropertyPriority("opacity"),
|
||||
inert: host.hasAttribute("inert"),
|
||||
};
|
||||
host.style.setProperty("opacity", "0", "important");
|
||||
host.setAttribute("inert", "");
|
||||
return opacity;
|
||||
});
|
||||
return () =>
|
||||
hidden.forEach((host, i) => {
|
||||
const ours =
|
||||
host.style.getPropertyValue("opacity") === "0" &&
|
||||
host.style.getPropertyPriority("opacity") === "important";
|
||||
const { value, priority, inert } = opacities[i]!;
|
||||
if (ours && value) host.style.setProperty("opacity", value, priority);
|
||||
else if (ours) host.style.removeProperty("opacity");
|
||||
if (!inert) host.removeAttribute("inert");
|
||||
if (displayBeforeHide.has(host)) host.style.display = "none";
|
||||
});
|
||||
};
|
||||
const runSceneScripts = async (hosts: Element[], scripts: Element[]) => {
|
||||
const putHidesBack = layOutHiddenHosts(hosts);
|
||||
try {
|
||||
await runSceneScriptsLaidOut(hosts, scripts);
|
||||
} finally {
|
||||
putHidesBack();
|
||||
}
|
||||
};
|
||||
// Runs a scene's scripts, then records what they started after returning: a script resumed by a font
|
||||
// wait builds there, past the recorder that wraps it. With several scenes, a late animation's scene is unknown.
|
||||
const runSceneScripts = async (hosts: Element[], scripts: Element[]) => {
|
||||
const runSceneScriptsLaidOut = async (hosts: Element[], scripts: Element[]) => {
|
||||
const globalTimeline = window.gsap?.globalTimeline;
|
||||
const before = new Set<unknown>(globalTimeline?.getChildren?.(false, true, true));
|
||||
await runScriptsAfterFonts(scripts);
|
||||
|
||||
Reference in New Issue
Block a user