Skip to content

Commit 1519e7c

Browse files
committed
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.
1 parent dc8cac4 commit 1519e7c

7 files changed

Lines changed: 155 additions & 51 deletions

File tree

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

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ function copyPitches(offsets: number[]): number[] {
232232
}
233233

234234
const originalGetComputedStyle = globalThis.getComputedStyle;
235+
/** The marker sharp 0 sets on a moving target; a stylesheet rule does the hiding. */
236+
const HIDING = "data-hf-motion-blur-hiding";
235237

236238
beforeEach(() => {
237239
// The snippet polls the registry on a timer for seconds. Fake timers let a test reach the
@@ -315,37 +317,53 @@ describe("motion-blur shutter matches the After Effects reference", () => {
315317
// group has to precede the element rather than follow it.
316318
expect(group.nextElementSibling).toBe(word);
317319
expect(word.style.opacity).toBe("");
320+
expect(word.hasAttribute(HIDING)).toBe(false);
321+
expect(word.style.visibility).toBe("");
318322
});
319323

320324
it("leaves only the shutter average while moving at sharp 0, and the element at rest", async () => {
321325
let speed = 1;
322326
const { group, word, fire } = await attach({ sharp: 0 }, (df) => translating(df * speed));
323327

324328
expect(group.style.display).toBe("");
325-
expect(word.style.visibility).toBe("hidden");
329+
expect(word.hasAttribute(HIDING)).toBe(true);
326330

327331
speed = 0;
328332
fire();
329333
await Promise.resolve();
330334

331335
expect(group.style.display).toBe("none");
332-
expect(word.style.visibility).toBe("");
336+
expect(word.hasAttribute(HIDING)).toBe(false);
337+
});
338+
339+
it("leaves the element's own visibility to the timeline at sharp 0", async () => {
340+
// An autoAlpha fade writes visibility itself; hiding through it would keep the element
341+
// hidden after the fade brings it back.
342+
let speed = 1;
343+
const { word, fire } = await attach({ sharp: 0 }, (df) => translating(df * speed));
344+
word.style.visibility = "inherit";
345+
346+
speed = 0;
347+
fire();
348+
await Promise.resolve();
349+
350+
expect(word.style.visibility).toBe("inherit");
333351
});
334352

335353
it("styles the copies from the shown element when a resize lands while sharp 0 hides it", async () => {
336354
const observer = installResizeObserver();
337355
const { word } = await attach({ sharp: 0 });
338-
const seen: string[] = [];
356+
const seen: boolean[] = [];
339357
const mocked = globalThis.getComputedStyle;
340358
globalThis.getComputedStyle = ((element: Element) => {
341-
if (element === word) seen.push(word.style.visibility);
359+
if (element === word) seen.push(word.hasAttribute(HIDING));
342360
return mocked(element);
343361
}) as typeof globalThis.getComputedStyle;
344362

345363
observer.resize();
346364

347-
expect(seen[0]).toBe("");
348-
expect(word.style.visibility).toBe("hidden");
365+
expect(seen[0]).toBe(false);
366+
expect(word.hasAttribute(HIDING)).toBe(true);
349367
});
350368

351369
it("carries the element's own opacity on the smear", async () => {
@@ -796,6 +814,18 @@ describe("motion-blur declarative attribute, the cases only executing found", ()
796814
expect(leading).toBeCloseTo(reference.leadingDisplacementPx, 1);
797815
});
798816

817+
it("refuses a sharp other than 0 or 1 instead of reading it as crisp", async () => {
818+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
819+
const target = declare('{"sharp": 0.5}');
820+
821+
target.register();
822+
await target.settle();
823+
824+
expect(target.groups()).toHaveLength(0);
825+
expect(String(warn.mock.calls[0]?.[0])).toContain("needs 0 or 1 for sharp");
826+
warn.mockRestore();
827+
});
828+
799829
it("refuses an option name it does not know instead of rendering with the defaults", async () => {
800830
// The likeliest typo in a JSON object is the key, and reading it as defaults is exactly
801831
// the silent no-op the attribute exists to remove.

‎registry/blocks/gooey-split/gooey-split.html‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@
158158
// descendant. Any one left behind is swept as a target of its own, which clones again.
159159
var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];
160160

161+
// sharp 0 hides a moving target through this marker rather than its own visibility,
162+
// which the author's timeline (autoAlpha) may be writing too.
163+
var HIDE_ATTR = "data-hf-motion-blur-hiding";
164+
165+
function installHideRule() {
166+
if (document.getElementById("hf-mb-hide")) return;
167+
var rule = document.createElement("style");
168+
rule.id = "hf-mb-hide";
169+
rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";
170+
(document.head || document.documentElement).appendChild(rule);
171+
}
172+
161173
function stripAttrs(el) {
162174
for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);
163175
}
@@ -244,7 +256,8 @@
244256
var shutterAngle = numOption(opts.shutterAngle, 720);
245257
var shutterPhase = numOption(opts.shutterPhase, -360);
246258
var requestedSamples = numOption(opts.samplesPerFrame, 16);
247-
var sharp = numOption(opts.sharp, 1) !== 0;
259+
var sharp = opts.sharp !== 0;
260+
if (!sharp) installHideRule();
248261
var samples = Number.isFinite(requestedSamples)
249262
? Math.max(2, Math.min(64, Math.round(requestedSamples)))
250263
: 16;
@@ -323,7 +336,6 @@
323336
samples: [],
324337
perspective: "",
325338
watch: null,
326-
shown: el.style.visibility,
327339
};
328340

329341
// Resolved styles and the parent's perspective are px once read, so a
@@ -332,10 +344,10 @@
332344
// on a fixed-size render and keeps a live preview honest.
333345
function snapshot() {
334346
// A copy styled while sharp 0 hides the element would inherit the hiding.
335-
var hiding = el.style.visibility;
336-
if (!sharp) el.style.visibility = s.shown;
347+
var hiding = el.hasAttribute(HIDE_ATTR);
348+
if (hiding) el.removeAttribute(HIDE_ATTR);
337349
var styles = resolvedStyles(el, []);
338-
el.style.visibility = hiding;
350+
if (hiding) el.setAttribute(HIDE_ATTR, "");
339351
s.perspective = parentPerspective(el);
340352
for (var c = 0; c < clones.length; c++) {
341353
paintResolvedStyles(clones[c], styles, { i: 0 });
@@ -444,7 +456,7 @@
444456
}
445457
if (!moved) {
446458
s.group.style.display = "none";
447-
if (!sharp) s.el.style.visibility = s.shown;
459+
if (!sharp) s.el.removeAttribute(HIDE_ATTR);
448460
return;
449461
}
450462

@@ -471,7 +483,7 @@
471483
// own opacity is the 1/N shutter weight.
472484
s.group.style.opacity = current.opacity;
473485
s.group.style.display = "";
474-
if (!sharp) s.el.style.visibility = "hidden";
486+
if (!sharp) s.el.setAttribute(HIDE_ATTR, "");
475487
});
476488
}
477489

@@ -525,6 +537,9 @@
525537
if (bad !== null) return refuse(el, "names no such option: " + bad);
526538
var wrong = nonNumber(parsed);
527539
if (wrong !== null) return refuse(el, "needs a number for " + wrong);
540+
if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {
541+
return refuse(el, "needs 0 or 1 for sharp");
542+
}
528543
return parsed;
529544
}
530545

‎registry/components/motion-blur/demo.html‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,18 @@
280280
// descendant. Any one left behind is swept as a target of its own, which clones again.
281281
var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];
282282

283+
// sharp 0 hides a moving target through this marker rather than its own visibility,
284+
// which the author's timeline (autoAlpha) may be writing too.
285+
var HIDE_ATTR = "data-hf-motion-blur-hiding";
286+
287+
function installHideRule() {
288+
if (document.getElementById("hf-mb-hide")) return;
289+
var rule = document.createElement("style");
290+
rule.id = "hf-mb-hide";
291+
rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";
292+
(document.head || document.documentElement).appendChild(rule);
293+
}
294+
283295
function stripAttrs(el) {
284296
for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);
285297
}
@@ -366,7 +378,8 @@
366378
var shutterAngle = numOption(opts.shutterAngle, 720);
367379
var shutterPhase = numOption(opts.shutterPhase, -360);
368380
var requestedSamples = numOption(opts.samplesPerFrame, 16);
369-
var sharp = numOption(opts.sharp, 1) !== 0;
381+
var sharp = opts.sharp !== 0;
382+
if (!sharp) installHideRule();
370383
var samples = Number.isFinite(requestedSamples)
371384
? Math.max(2, Math.min(64, Math.round(requestedSamples)))
372385
: 16;
@@ -445,7 +458,6 @@
445458
samples: [],
446459
perspective: "",
447460
watch: null,
448-
shown: el.style.visibility,
449461
};
450462

451463
// Resolved styles and the parent's perspective are px once read, so a
@@ -454,10 +466,10 @@
454466
// on a fixed-size render and keeps a live preview honest.
455467
function snapshot() {
456468
// A copy styled while sharp 0 hides the element would inherit the hiding.
457-
var hiding = el.style.visibility;
458-
if (!sharp) el.style.visibility = s.shown;
469+
var hiding = el.hasAttribute(HIDE_ATTR);
470+
if (hiding) el.removeAttribute(HIDE_ATTR);
459471
var styles = resolvedStyles(el, []);
460-
el.style.visibility = hiding;
472+
if (hiding) el.setAttribute(HIDE_ATTR, "");
461473
s.perspective = parentPerspective(el);
462474
for (var c = 0; c < clones.length; c++) {
463475
paintResolvedStyles(clones[c], styles, { i: 0 });
@@ -566,7 +578,7 @@
566578
}
567579
if (!moved) {
568580
s.group.style.display = "none";
569-
if (!sharp) s.el.style.visibility = s.shown;
581+
if (!sharp) s.el.removeAttribute(HIDE_ATTR);
570582
return;
571583
}
572584

@@ -593,7 +605,7 @@
593605
// own opacity is the 1/N shutter weight.
594606
s.group.style.opacity = current.opacity;
595607
s.group.style.display = "";
596-
if (!sharp) s.el.style.visibility = "hidden";
608+
if (!sharp) s.el.setAttribute(HIDE_ATTR, "");
597609
});
598610
}
599611

@@ -647,6 +659,9 @@
647659
if (bad !== null) return refuse(el, "names no such option: " + bad);
648660
var wrong = nonNumber(parsed);
649661
if (wrong !== null) return refuse(el, "needs a number for " + wrong);
662+
if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {
663+
return refuse(el, "needs 0 or 1 for sharp");
664+
}
650665
return parsed;
651666
}
652667

‎registry/components/motion-blur/motion-blur.html‎

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,8 @@
115115
sharp — 1 (default) paints the element itself, crisp, over its
116116
smear; 0 hides it while it moves, leaving only the
117117
shutter average: a soft blur with no frame-time edge.
118-
At rest it restores the visibility the element had
119-
when blurred, so do not animate visibility (autoAlpha)
120-
on a sharp 0 target
118+
It hides through a marker attribute, never the
119+
element's own visibility, so autoAlpha still works
121120
122121
A key that is none of the five, or a value that is not a finite number, is
123122
refused by name rather than read as defaults. Both halves matter: a
@@ -149,6 +148,18 @@
149148
// descendant. Any one left behind is swept as a target of its own, which clones again.
150149
var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];
151150

151+
// sharp 0 hides a moving target through this marker rather than its own visibility,
152+
// which the author's timeline (autoAlpha) may be writing too.
153+
var HIDE_ATTR = "data-hf-motion-blur-hiding";
154+
155+
function installHideRule() {
156+
if (document.getElementById("hf-mb-hide")) return;
157+
var rule = document.createElement("style");
158+
rule.id = "hf-mb-hide";
159+
rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";
160+
(document.head || document.documentElement).appendChild(rule);
161+
}
162+
152163
function stripAttrs(el) {
153164
for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);
154165
}
@@ -235,7 +246,8 @@
235246
var shutterAngle = numOption(opts.shutterAngle, 720);
236247
var shutterPhase = numOption(opts.shutterPhase, -360);
237248
var requestedSamples = numOption(opts.samplesPerFrame, 16);
238-
var sharp = numOption(opts.sharp, 1) !== 0;
249+
var sharp = opts.sharp !== 0;
250+
if (!sharp) installHideRule();
239251
var samples = Number.isFinite(requestedSamples)
240252
? Math.max(2, Math.min(64, Math.round(requestedSamples)))
241253
: 16;
@@ -314,7 +326,6 @@
314326
samples: [],
315327
perspective: "",
316328
watch: null,
317-
shown: el.style.visibility,
318329
};
319330

320331
// Resolved styles and the parent's perspective are px once read, so a
@@ -323,10 +334,10 @@
323334
// on a fixed-size render and keeps a live preview honest.
324335
function snapshot() {
325336
// A copy styled while sharp 0 hides the element would inherit the hiding.
326-
var hiding = el.style.visibility;
327-
if (!sharp) el.style.visibility = s.shown;
337+
var hiding = el.hasAttribute(HIDE_ATTR);
338+
if (hiding) el.removeAttribute(HIDE_ATTR);
328339
var styles = resolvedStyles(el, []);
329-
el.style.visibility = hiding;
340+
if (hiding) el.setAttribute(HIDE_ATTR, "");
330341
s.perspective = parentPerspective(el);
331342
for (var c = 0; c < clones.length; c++) {
332343
paintResolvedStyles(clones[c], styles, { i: 0 });
@@ -435,7 +446,7 @@
435446
}
436447
if (!moved) {
437448
s.group.style.display = "none";
438-
if (!sharp) s.el.style.visibility = s.shown;
449+
if (!sharp) s.el.removeAttribute(HIDE_ATTR);
439450
return;
440451
}
441452

@@ -462,7 +473,7 @@
462473
// own opacity is the 1/N shutter weight.
463474
s.group.style.opacity = current.opacity;
464475
s.group.style.display = "";
465-
if (!sharp) s.el.style.visibility = "hidden";
476+
if (!sharp) s.el.setAttribute(HIDE_ATTR, "");
466477
});
467478
}
468479

@@ -516,6 +527,9 @@
516527
if (bad !== null) return refuse(el, "names no such option: " + bad);
517528
var wrong = nonNumber(parsed);
518529
if (wrong !== null) return refuse(el, "needs a number for " + wrong);
530+
if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {
531+
return refuse(el, "needs 0 or 1 for sharp");
532+
}
519533
return parsed;
520534
}
521535

0 commit comments

Comments
 (0)