Skip to content

Commit b50dead

Browse files
feat(registry): gooey split block with metaball goo and directional motion blur (#5123)
* feat(registry): gooey split block with metaball goo and directional motion blur A dot splits into a three-dot menu through a gooey neck, spins into a swirl mark under shutter motion blur, breaks back into three dots and merges into one. Timing, spacing and eases are measured off a reference recording frame by frame. The motion-blur snippet gains an opt-in `sharp: 0` option that hides the crisp frame-time copy while an element moves, leaving only the shutter average. The default is unchanged; the inlined copies carry the same text. * feat(registry): grow gooey-split blades out of swelling dots * refactor(registry): tidy gooey-split pose code and document sharp 0 limits * fix(registry): hide a sharp 0 motion-blur target by marker, not its visibility Hiding through the element's own visibility fought timelines that write it (autoAlpha): a target faded in after attach stayed hidden at rest. A marker attribute and one !important rule now do the hiding, the default path writes nothing, and a declarative sharp other than 0 or 1 is refused like any other bad option. * fix(registry): smear a motion-blur target that was hidden when blur attached Copies froze the target's computed visibility at attach, so a target entering with autoAlpha never smeared (and vanished entirely under sharp 0). The group now carries the target's current visibility each frame, read with the sharp 0 marker lifted, and a copy keeps a descendant's visibility only where it differs from its parent's. * test(registry): pin a copy keeping a descendant's own visibility * fix(registry): keep a child's own hiding in the smear of a target hidden at attach * refactor(registry): restore a lifted visibility in one call and lift any hidden form * fix(registry): restore a lifted visibility even when copying styles throws * fix(registry): let motion-blur copies hide with a clip that has ended The smear group set an explicit visibility on every moving frame, and copies used to freeze an explicit visible, so an ancestor clip hiding after the last update could not hide them: copies from a 0-4 s sub-composition stayed on screen at 16.4 s. The group now sets a visibility only where the element's differs from its parent's. Also regenerates skills-manifest.json for the motion-blur skill doc.
1 parent 156e877 commit b50dead

9 files changed

Lines changed: 1350 additions & 38 deletions

File tree

‎packages/cli/src/registry/motionBlurShutter.browser.test.ts‎

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ function makeTimeline(onTo?: () => void): Fake {
116116
return { tl, currentTime: () => now, fire: () => onUpdate?.(), trackers: () => trackers };
117117
}
118118

119+
/** What the browser resolves for the target: an inline !important, else the marker's rule, else the inline value. */
120+
function wordVisibility(word: Element): string {
121+
const style = (word as HTMLElement).style;
122+
if (style.getPropertyPriority("visibility") === "important") return style.visibility;
123+
if (word.hasAttribute(HIDING)) return "hidden";
124+
return style.visibility || "visible";
125+
}
126+
119127
/**
120128
* happy-dom resolves no transforms of its own, so the element's computed style is the trajectory.
121129
* The stub also answers the declaration enumeration the style replay uses, and the perspective.
@@ -135,6 +143,7 @@ function installComputedStyle(
135143
transformOrigin: "50% 50%",
136144
opacity: element === word ? opacity() : "1",
137145
perspective: element === word ? "none" : perspective(),
146+
visibility: element === word ? wordVisibility(word) : "visible",
138147
}) as unknown as CSSStyleDeclaration) as typeof globalThis.getComputedStyle;
139148
}
140149

@@ -232,6 +241,8 @@ function copyPitches(offsets: number[]): number[] {
232241
}
233242

234243
const originalGetComputedStyle = globalThis.getComputedStyle;
244+
/** The marker sharp 0 sets on a moving target; a stylesheet rule does the hiding. */
245+
const HIDING = "data-hf-motion-blur-hiding";
235246

236247
beforeEach(() => {
237248
// The snippet polls the registry on a timer for seconds. Fake timers let a test reach the
@@ -255,12 +266,13 @@ afterEach(async () => {
255266

256267
describe("motion-blur snippet copies", () => {
257268
// The demos and the example composition have to inline the snippet — a catalog plate is a single
258-
// self-contained file and cannot import one. That makes four copies of the same shutter model, so
269+
// self-contained file and cannot import one. That makes five copies of the same shutter model, so
259270
// the copies are asserted equal here rather than left to drift silently.
260271
it.each([
261272
"registry/components/motion-blur/demo.html",
262273
"registry/components/shutter-slam/shutter-slam.html",
263274
"registry/components/shutter-slam/demo.html",
275+
"registry/blocks/gooey-split/gooey-split.html",
264276
])("%s inlines the installable snippet verbatim", (relativePath) => {
265277
expect(snippetBody(readRepoFile(relativePath))).toBe(snippetBody(snippetHtml));
266278
});
@@ -314,6 +326,87 @@ describe("motion-blur shutter matches the After Effects reference", () => {
314326
// group has to precede the element rather than follow it.
315327
expect(group.nextElementSibling).toBe(word);
316328
expect(word.style.opacity).toBe("");
329+
expect(word.hasAttribute(HIDING)).toBe(false);
330+
expect(word.style.visibility).toBe("");
331+
});
332+
333+
it("leaves only the shutter average while moving at sharp 0, and the element at rest", async () => {
334+
let speed = 1;
335+
const { group, word, fire } = await attach({ sharp: 0 }, (df) => translating(df * speed));
336+
337+
expect(group.style.display).toBe("");
338+
expect(word.hasAttribute(HIDING)).toBe(true);
339+
340+
speed = 0;
341+
fire();
342+
await Promise.resolve();
343+
344+
expect(group.style.display).toBe("none");
345+
expect(word.hasAttribute(HIDING)).toBe(false);
346+
});
347+
348+
it("leaves the element's own visibility to the timeline at sharp 0", async () => {
349+
// An autoAlpha fade writes visibility itself; hiding through it would keep the element
350+
// hidden after the fade brings it back.
351+
let speed = 1;
352+
const { word, fire } = await attach({ sharp: 0 }, (df) => translating(df * speed));
353+
word.style.visibility = "inherit";
354+
355+
speed = 0;
356+
fire();
357+
await Promise.resolve();
358+
359+
expect(word.style.visibility).toBe("inherit");
360+
});
361+
362+
it("smears in the element's current visibility, read without its own marker", async () => {
363+
// A second frame starts with the marker set, so a read that did not lift it would hide
364+
// the smear along with the element.
365+
const { group, word, fire } = await attach({ sharp: 0 });
366+
fire();
367+
await Promise.resolve();
368+
369+
expect(word.hasAttribute(HIDING)).toBe(true);
370+
expect(group.style.visibility).toBe("");
371+
});
372+
373+
it("leaves the smear's visibility to an ancestor while the element shares it", async () => {
374+
// A clip that ends hides its subtree after the last moving frame; an explicit visible on
375+
// the group would keep the copies on screen past it.
376+
const { group } = await attach();
377+
378+
expect(group.style.display).toBe("");
379+
expect(group.style.visibility).toBe("");
380+
});
381+
382+
it("hides the smear with an element the timeline hides", async () => {
383+
const { group, word, fire } = await attach();
384+
word.style.visibility = "hidden";
385+
fire();
386+
await Promise.resolve();
387+
388+
expect(group.style.visibility).toBe("hidden");
389+
});
390+
391+
it("does not freeze the element's visibility into the copies", async () => {
392+
// An element attached while an autoAlpha entrance still hides it would otherwise smear
393+
// as nothing for the rest of the timeline.
394+
const observer = installResizeObserver();
395+
const { word, copies } = await attach();
396+
const mocked = globalThis.getComputedStyle;
397+
globalThis.getComputedStyle = ((element: Element) => {
398+
if (element !== word) return mocked(element);
399+
const values: Record<string, string> = { visibility: "hidden", color: "red" };
400+
return Object.assign(Object.create(mocked(element)), Object.keys(values), {
401+
length: 2,
402+
getPropertyValue: (name: string) => values[name] ?? "",
403+
});
404+
}) as typeof globalThis.getComputedStyle;
405+
406+
observer.resize();
407+
408+
expect(copies[0]?.style.color).toBe("red");
409+
expect(copies[0]?.style.visibility).toBe("");
317410
});
318411

319412
it("carries the element's own opacity on the smear", async () => {
@@ -501,6 +594,61 @@ describe("motion-blur declarative attribute", () => {
501594
expect(target.groups()[0]?.children).toHaveLength(5);
502595
});
503596

597+
it("keeps a descendant's own hiding in a copy of a target hidden at attach", async () => {
598+
// An autoAlpha entrance hides the target when it is blurred. A child hidden by its own
599+
// rule must still differ from it, or the smear would show what the element hides.
600+
const target = declare("");
601+
const own = document.createElement("span");
602+
const inheriting = document.createElement("span");
603+
target.word.append(own, inheriting);
604+
target.word.style.setProperty("visibility", "hidden", "important");
605+
const mocked = globalThis.getComputedStyle;
606+
const resolved = (element: Element, value: string) =>
607+
Object.assign(Object.create(mocked(element)), ["visibility"], {
608+
length: 1,
609+
visibility: value,
610+
getPropertyValue: (name: string) => (name === "visibility" ? value : ""),
611+
});
612+
globalThis.getComputedStyle = ((element: Element) => {
613+
if (element === own) return resolved(element, "hidden");
614+
if (element === inheriting || element === target.word) {
615+
return resolved(element, wordVisibility(target.word));
616+
}
617+
return mocked(element);
618+
}) as typeof globalThis.getComputedStyle;
619+
620+
target.register();
621+
target.fire();
622+
await Promise.resolve();
623+
624+
const copy = target.groups()[0]?.children[0];
625+
if (!copy) throw new Error("motion-blur group carries no copies");
626+
expect((copy.children[0] as HTMLElement).style.visibility).toBe("hidden");
627+
expect((copy.children[1] as HTMLElement).style.visibility).toBe("");
628+
expect(target.word.style.visibility).toBe("hidden");
629+
expect(target.word.style.getPropertyPriority("visibility")).toBe("important");
630+
});
631+
632+
it("puts a hidden target's visibility back when copying its styles throws", async () => {
633+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
634+
const target = declare("");
635+
const child = document.createElement("span");
636+
target.word.append(child);
637+
target.word.style.visibility = "hidden";
638+
const mocked = globalThis.getComputedStyle;
639+
globalThis.getComputedStyle = ((element: Element) => {
640+
if (element === child) throw new Error("no style");
641+
return mocked(element);
642+
}) as typeof globalThis.getComputedStyle;
643+
644+
target.register();
645+
646+
expect(target.groups()).toHaveLength(0);
647+
expect(target.word.style.visibility).toBe("hidden");
648+
expect(target.word.style.getPropertyPriority("visibility")).toBe("");
649+
warn.mockRestore();
650+
});
651+
504652
it("leaves a target alone when another composition registers", async () => {
505653
// One page can hold several compositions, and a target belongs to the nearest one.
506654
const target = declare("");
@@ -764,6 +912,18 @@ describe("motion-blur declarative attribute, the cases only executing found", ()
764912
expect(leading).toBeCloseTo(reference.leadingDisplacementPx, 1);
765913
});
766914

915+
it("refuses a sharp other than 0 or 1 instead of reading it as crisp", async () => {
916+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
917+
const target = declare('{"sharp": 0.5}');
918+
919+
target.register();
920+
await target.settle();
921+
922+
expect(target.groups()).toHaveLength(0);
923+
expect(String(warn.mock.calls[0]?.[0])).toContain("needs 0 or 1 for sharp");
924+
warn.mockRestore();
925+
});
926+
767927
it("refuses an option name it does not know instead of rendering with the defaults", async () => {
768928
// The likeliest typo in a JSON object is the key, and reading it as defaults is exactly
769929
// the silent no-op the attribute exists to remove.

0 commit comments

Comments
 (0)