Skip to content

Write HTML. Render video. Built for agents.

fix(registry): make motion-blur match After Effects shutter-based blur (#4008)

miga-heygen9aa60a844fa6
diff --git a/docs/catalog/components/motion-blur.mdx b/docs/catalog/components/motion-blur.mdx
index e0d40c9267..23c6c84147 100644
--- a/docs/catalog/components/motion-blur.mdx
+++ b/docs/catalog/components/motion-blur.mdx
@@ -1,6 +1,6 @@
---
title: "Motion Blur"
-description: "Velocity-driven motion blur — samples element position each frame and applies a one-sided SVG feGaussianBlur ghost trail proportional to speed"
+description: "After Effects-style motion blur — integrates each element over a shutter window (shutter angle, phase, samples per frame) by sampling the GSAP timeline at sub-frame times and averaging equal-weight SVG copies along the real trajectory"
---
import { InstallCommand } from "/snippets/install-command.jsx";
@@ -24,50 +24,158 @@ That writes one file: `compositions/components/motion-blur.html`.
```html
<!--
- Motion Blur — velocity-driven directional motion blur.
+ Motion Blur — After Effects-style shutter-based motion blur.
Usage: paste this snippet into your composition, then call
attachMotionBlur() with any element animated by your GSAP timeline.
- The snippet hooks into the timeline's onUpdate callback, tracks the
- GSAP x/y position of each target frame-by-frame, and applies:
- 1. Ghost copies of the element at increasing backward offsets with
- decreasing opacity — inherently one-sided, no forward blur component.
- 2. A small Gaussian blur at the current position so the element looks
- in-motion (blurry) rather than sharp on top of the trail.
- 3. An optional scaleX/Y stretch in the direction of travel (off by
- default; enable via stretchMax > 0 if you want the effect).
-
- Both effects clear automatically when the element decelerates to rest.
+ How it works — the same model After Effects uses for the layer Motion Blur
+ switch (temporal supersampling), synthesised inside the page because the
+ renderer captures one instant per frame with no shutter:
+
+ 1. After every timeline update (each rendered frame), the snippet seeks
+ the timeline to `samplesPerFrame` sub-frame times spread evenly across
+ the shutter window, reads each target's GSAP x/y at every sample, then
+ restores the frame time. Seeks run with events suppressed, so no user
+ callbacks fire and the DOM ends up exactly where the frame left it.
+ 2. An SVG filter stacks one copy of the element per sample (feOffset to
+ the sampled position relative to the current one) and adds them at
+ equal weight (feComposite arithmetic, 1/N each, sRGB space). Result:
+ a box smear along the actual trajectory whose length is speed ×
+ shutter time, with no decaying one-sided trail. The tails — where
+ fewer copies overlap — step down evenly at 1/N per copy; wherever the
+ element travels less than its own size the copies pile up past 1 and
+ clamp, so the middle of the smear is solid rather than a plateau.
+ 3. The element itself is then composited over that smear, sharp and at
+ full opacity. No single duplicate ever exceeds 1/N, so a moving edge
+ resolves as a staircase of ghosts behind a solid frame-time instance.
+ 4. When the sampled positions collapse to the current one (element at
+ rest), the filter is removed so the element renders sharp.
+
+ Shutter window (AE semantics, per frame at time t, frame interval 1/fps):
+ shutterTime = shutterAngle / 360 / fps
+ windowStart = t + shutterPhase / 360 / fps
+ copy k = windowStart + k / N × shutterTime, k = 0..N (N+1 copies)
+ N counts sub-intervals, so both ends of the window carry a copy.
+ Defaults (shutterAngle 720, shutterPhase -360) integrate [t - 1/fps, t + 1/fps]:
+ a solid moving at 2000 px/s at 30 fps smears 133 px, centred on its position.
+
+ These defaults are measured, not assumed. On a 1920×1080 / 30 fps After Effects
+ export of translating text, the outermost duplicate on the trailing side sits
+ exactly at the previous frame's position and the outermost leading duplicate
+ exactly at the next frame's, with 8 evenly spaced duplicates in between on each
+ side (window = 2 frames = 720°, phase -360°, 16 sub-intervals). Reading the ghost
+ staircase across a stroke gives steps of 0.063 ± 0.002 of the sharp text
+ intensity — a flat 1/16 per duplicate, with no taper toward the window edges
+ (triangle weighting scores 1.6 dB worse against the same export). The sharp
+ instance on top is what keeps total ink above the unblurred frame's.
Requirements:
- - Elements must be animated via GSAP x/y (transform), not left/top.
- - Call attachMotionBlur() AFTER defining all tweens, before
- window.__timelines registration.
+ - Elements must be animated via GSAP x/y (transform), not left/top. The
+ element's own scale/rotation is compensated; skew, 3D rotation and
+ transformed ancestors are not.
+ - The host must render the timeline for the blur to update — HyperFrames
+ seeks every frame. A fresh paused timeline that is never seeked shows no
+ blur on its first frame.
+ - Call attachMotionBlur() AFTER defining all tweens (the timeline's final
+ duration must be known), before window.__timelines registration.
- GSAP must be loaded before this snippet executes.
API:
attachMotionBlur(selector, timeline, options?)
Options:
- blurScale — directional blur per px/s of velocity (default 0.008)
- blurMax — max blur radius on the motion axis in px (default 20)
- stretchScale — scaleX/Y added per px/s (default 0.0002)
- stretchMax — max stretch factor above 1.0 (default 0, disabled)
- axis — "x" | "y" | "both" (default "both")
+ shutterAngle — degrees of the frame interval the shutter is open
+ (default 720 = two frames, as measured off the AE
+ reference; 360 = one frame, 0 disables)
+ shutterPhase — degrees offset of the window start from the frame
+ time (default -360 = centred on the frame, one frame
+ back, like the AE reference)
+ samplesPerFrame — sub-intervals of the shutter window, so N+1 duplicates
+ each at 1/N opacity (default 16, max 64)
+ fps — composition frame rate (default: the root's data-fps,
+ else 30). Pass it explicitly when rendering with an
+ fps override (`hyperframes render --fps`).
+ axis — "x" | "y" | "both" (default "both")
-->
<script>
(function () {
if (!window._hfMbUid) window._hfMbUid = 0;
+ // Shutter length is measured in frames, so the snippet must know the
+ // composition frame rate: explicit option, else the root's data-fps, else 30.
+ function resolveFps(optionFps) {
+ var explicit = Number(optionFps);
+ if (explicit > 0) return explicit;
+
+ var root = document.querySelector("[data-composition-id][data-fps]");
+ var rootFps = root ? Number(root.getAttribute("data-fps")) : 0;
+ if (rootFps > 0) return rootFps;
+
+ return 30;
+ }
+
+ function numOption(value, fallback) {
+ return value !== undefined ? Number(value) : fallback;
+ }
+
+ // objectBoundingBox percentage for a px offset plus padding.
+ function regionPercent(offset, size, padPercent) {
+ return ((offset / size) * 100 + padPercent).toFixed(2) + "%";
+ }
+
window.attachMotionBlur = function (selector, tl, opts) {
opts = opts || {};
- var blurScale = opts.blurScale !== undefined ? opts.blurScale : 0.008;
- var blurMax = opts.blurMax !== undefined ? opts.blurMax : 20;
- var stretchScale = opts.stretchScale !== undefined ? opts.stretchScale : 0.0002;
- var stretchMax = opts.stretchMax !== undefined ? opts.stretchMax : 0;
+ var shutterAngle = numOption(opts.shutterAngle, 720);
+ var shutterPhase = numOption(opts.shutterPhase, -360);
+ var requestedSamples = numOption(opts.samplesPerFrame, 16);
+ var samples = Number.isFinite(requestedSamples)
+ ? Math.max(2, Math.min(64, Math.round(requestedSamples)))
+ : 16;
var axis = opts.axis || "both";
+ var fps = resolveFps(opts.fps);
+ var useX = axis !== "y";
+ var useY = axis !== "x";
+
+ // Untransformed box size; SVG elements have no offsetWidth, so use the
+ // same bbox GSAP uses to resolve their percent transforms.
+ function boxSize(el, horizontal) {
+ var box = typeof el.offsetWidth === "number" ? el : el.getBBox ? el.getBBox() : null;
+ var size = box
+ ? horizontal
+ ? box.offsetWidth || box.width
+ : box.offsetHeight || box.height
+ : 0;
+ return size || el.getBoundingClientRect()[horizontal ? "width" : "height"] || 1;
+ }
+
+ // GSAP x/y may carry a % unit and xPercent/yPercent is a separate term;
+ // resolve both against the element's own box so samples are in px.
+ function readAxis(el, prop, percentProp, size) {
+ var px = parseFloat(gsap.getProperty(el, prop, "px")) || 0;
+ var percent = parseFloat(gsap.getProperty(el, percentProp)) || 0;
+ return px + (percent * size) / 100;
+ }
+
+ function readPosition(el) {
+ return {
+ x: useX ? readAxis(el, "x", "xPercent", boxSize(el, true)) : 0,
+ y: useY ? readAxis(el, "y", "yPercent", boxSize(el, false)) : 0,
+ };
+ }
+
+ // CSS filters run in the element's pre-transform space while GSAP x/y are
+ // post-transform, so a displacement is mapped through the inverse of the
+ // element's own scale/rotation. Ancestor transforms are not compensated.
+ function toFilterSpace(el, dx, dy) {
+ var sx = parseFloat(gsap.getProperty(el, "scaleX")) || 1;
+ var sy = parseFloat(gsap.getProperty(el, "scaleY")) || 1;
+ var theta = ((parseFloat(gsap.getProperty(el, "rotation")) || 0) * Math.PI) / 180;
+ var cos = Math.cos(theta);
+ var sin = Math.sin(theta);
+ return { dx: (dx * cos + dy * sin) / sx, dy: (-dx * sin + dy * cos) / sy };
+ }
var items = Array.isArray(selector) ? selector : [selector];
var targets = items.reduce(function (acc, s) {
@@ -81,15 +189,17 @@ That writes one file: `compositions/components/motion-blur.html`.
return acc;
}, []);
- // One SVG filter per target. Ghost copies placed behind → inherently one-sided.
- // Small top Gaussian makes element look blurry at current position, not sharp.
var ns = "http://www.w3.org/2000/svg";
- var GHOST_CFG = [
- { frac: 0.25, slope: 0.55 },
- { frac: 0.55, slope: 0.28 },
- { frac: 1.0, slope: 0.1 },
- ];
-
+ // `samples` counts sub-intervals of the shutter window, so there is one copy at
+ // every interval boundary — both ends of the window included — and each carries
+ // 1/samples of the source. That is what the reference export shows: the outermost
+ // copy sits exactly one frame away from the frame time, not half a step short.
+ var copies = samples + 1;
+ var weight = String(1 / samples);
+
+ // One SVG filter per target: N+1 offset copies of SourceGraphic added at 1/N
+ // each, then the element itself over the top. Accumulating in sRGB matches
+ // AE's default (non-linear) 8-bpc working space.
var state = targets.map(function (el) {
var uid = "hf-mb-" + window._hfMbUid++;
var svg = document.createElementNS(ns, "svg");
@@ -97,70 +207,147 @@ That writes one file: `compositions/components/motion-blur.html`.
var filter = document.createElementNS(ns, "filter");
filter.id = uid;
- filter.setAttribute("x", "-110%");
- filter.setAttribute("y", "-25%");
- filter.setAttribute("width", "260%");
- filter.setAttribute("height", "150%");
+ filter.setAttribute("color-interpolation-filters", "sRGB");
- var ghosts = GHOST_CFG.map(function (cfg, gi) {
+ var offsets = [];
+ for (var k = 0; k < copies; k++) {
var feOff = document.createElementNS(ns, "feOffset");
feOff.setAttribute("in", "SourceGraphic");
feOff.setAttribute("dx", "0");
feOff.setAttribute("dy", "0");
- feOff.setAttribute("result", "go" + gi);
-
- var feGB = document.createElementNS(ns, "feGaussianBlur");
- feGB.setAttribute("in", "go" + gi);
- feGB.setAttribute("stdDeviation", "0 0");
- feGB.setAttribute("result", "gb" + gi);
-
- var feCT = document.createElementNS(ns, "feComponentTransfer");
- feCT.setAttribute("in", "gb" + gi);
- feCT.setAttribute("result", "gf" + gi);
- var feFuncA = document.createElementNS(ns, "feFuncA");
- feFuncA.setAttribute("type", "linear");
- feFuncA.setAttribute("slope", String(cfg.slope));
- feCT.appendChild(feFuncA);
-
+ feOff.setAttribute("result", "s" + k);
filter.appendChild(feOff);
- filter.appendChild(feGB);
- filter.appendChild(feCT);
- return { feOff: feOff, feGB: feGB, frac: cfg.frac };
- });
+ offsets.push(feOff);
+ }
- var feTopBlur = document.createElementNS(ns, "feGaussianBlur");
- feTopBlur.setAttribute("in", "SourceGraphic");
- feTopBlur.setAttribute("stdDeviation", "0 0");
- feTopBlur.setAttribute("result", "top");
- filter.appendChild(feTopBlur);
-
- var feMerge = document.createElementNS(ns, "feMerge");
- for (var mi = GHOST_CFG.length - 1; mi >= 0; mi--) {
- var mn = document.createElementNS(ns, "feMergeNode");
- mn.setAttribute("in", "gf" + mi);
- feMerge.appendChild(mn);
+ // Pairwise accumulation: the first composite scales both inputs by 1/N, every
+ // later one adds the next copy at 1/N to the running sum. The N+1 weights total
+ // (N+1)/N, so an element wider than its own smear saturates through the middle
+ // and the filter clamps there. That is the saturation the reference shows, and
+ // the sharp instance covers the same region regardless.
+ var accumulated = "s0";
+ for (var c = 1; c < copies; c++) {
+ var feComp = document.createElementNS(ns, "feComposite");
+ feComp.setAttribute("operator", "arithmetic");
+ feComp.setAttribute("in", accumulated);
+ feComp.setAttribute("in2", "s" + c);
+ feComp.setAttribute("k1", "0");
+ feComp.setAttribute("k2", c === 1 ? weight : "1");
+ feComp.setAttribute("k3", weight);
+ feComp.setAttribute("k4", "0");
+ accumulated = "a" + c;
+ feComp.setAttribute("result", accumulated);
+ filter.appendChild(feComp);
}
- var mnTop = document.createElementNS(ns, "feMergeNode");
- mnTop.setAttribute("in", "top");
- feMerge.appendChild(mnTop);
- filter.appendChild(feMerge);
+
+ // The frame-time instance is drawn sharp, at full opacity, over the smear.
+ // Every blurred copy stays at 1/N, so nothing but the instance the frame is
+ // actually at reads as solid. Unnamed, so it is the filter output.
+ var feOver = document.createElementNS(ns, "feComposite");
+ feOver.setAttribute("operator", "over");
+ feOver.setAttribute("in", "SourceGraphic");
+ feOver.setAttribute("in2", accumulated);
+ filter.appendChild(feOver);
svg.appendChild(filter);
document.body.appendChild(svg);
- return {
- el: el,
- ghosts: ghosts,
- feTopBlur: feTopBlur,
- filterId: uid,
- prevX: parseFloat(gsap.getProperty(el, "x")) || 0,
- prevY: parseFloat(gsap.getProperty(el, "y")) || 0,
- prevTime: tl.time(),
- };
+ return { el: el, offsets: offsets, filter: filter, filterId: uid, xs: [], ys: [] };
});
- // tl.eventCallback("onUpdate") is not available in the HyperFrames renderer —
- // the runtime proxies the timeline object. Tween onUpdate fires on every seek.
+ // The element may carry its own inline filter (authored or tweened by
+ // GSAP); the blur is appended to that chain and removed from it, never
+ // written over it.
+ var OWN_FILTER = /\s*url\(["']?#hf-mb-\d+["']?\)/g;
+
+ function baseFilter(el) {
+ return el.style.filter.replace(OWN_FILTER, "").trim();
+ }
+
+ function clearBlur(s) {
+ s.el.style.filter = baseFilter(s.el);
+ }
+
+ var scheduled = false;
+
+ function applyShutter() {
+ var shutterTime = shutterAngle / 360 / fps;
+ if (!(shutterTime > 0)) {
+ state.forEach(clearBlur);
+ return;
+ }
+
+ var t0 = tl.time();
+ var duration = tl.duration();
+ var windowStart = t0 + shutterPhase / 360 / fps;
+
+ // Sample the real trajectory: seek to each sub-frame time with events
+ // suppressed (so no tween callbacks, including this tracker's, fire),
+ // read positions, then restore the frame time.
+ try {
+ for (var k = 0; k < copies; k++) {
+ var tk = windowStart + (k / samples) * shutterTime;
+ tl.time(Math.min(duration, Math.max(0, tk)), true);
+ state.forEach(function (s) {
+ var pos = readPosition(s.el);
+ s.xs[k] = pos.x;
+ s.ys[k] = pos.y;
+ });
+ }
+ } finally {
+ tl.time(t0, true);
+ }
+
+ state.forEach(function (s) {
+ var current = readPosition(s.el);
+ var minDx = Infinity;
+ var maxDx = -Infinity;
+ var minDy = Infinity;
+ var maxDy = -Infinity;
+ for (var i = 0; i < copies; i++) {
+ var d = toFilterSpace(s.el, s.xs[i] - current.x, s.ys[i] - current.y);
+ var dx = d.dx;
+ var dy = d.dy;
+ s.offsets[i].setAttribute("dx", dx.toFixed(3));
+ s.offsets[i].setAttribute("dy", dy.toFixed(3));
+ if (dx < minDx) minDx = dx;
+ if (dx > maxDx) maxDx = dx;
+ if (dy < minDy) minDy = dy;
+ if (dy > maxDy) maxDy = dy;
+ }
+
+ // Below half a pixel of smear the average is indistinguishable from
+ // the source — render sharp instead of paying for the filter.
+ if (maxDx - minDx < 0.5 && maxDy - minDy < 0.5) {
+ clearBlur(s);
+ return;
+ }
+
+ // Grow the filter region to cover every copy AND the sharp instance the
+ // final composite draws at offset 0 (objectBoundingBox units, 10% padding
+ // so anti-aliased edges are not clipped). Clamping the bounds through 0
+ // matters whenever the window sits entirely on one side of the frame time
+ // — any shutterPhase above 0 or below -shutterAngle — because then no copy
+ // is at 0 and a region derived from the copies alone cuts the instance off.
+ var x0 = Math.min(0, minDx);
+ var x1 = Math.max(0, maxDx);
+ var y0 = Math.min(0, minDy);
+ var y1 = Math.max(0, maxDy);
+ var w = boxSize(s.el, true);
+ var h = boxSize(s.el, false);
+ s.filter.setAttribute("x", regionPercent(x0, w, -10));
+ s.filter.setAttribute("width", regionPercent(x1 - x0, w, 120));
+ s.filter.setAttribute("y", regionPercent(y0, h, -10));
+ s.filter.setAttribute("height", regionPercent(y1 - y0, h, 120));
+ var base = baseFilter(s.el);
+ s.el.style.filter = (base ? base + " " : "") + "url(#" + s.filterId + ")";
+ });
+ }
+
+ // tl.eventCallback("onUpdate") is unavailable under the HyperFrames runtime proxy, so a
+ // tracker tween's onUpdate fires on every seek. Sampling is deferred to a microtask:
+ // seeking GSAP from inside its own render reads stale tween state, while the microtask
+ // runs after the seek returns and before the frame is captured or painted.
var _proxy = { t: 0 };
tl.to(
_proxy,
@@ -169,88 +356,11 @@ That writes one file: `compositions/components/motion-blur.html`.
duration: Math.max(tl.duration(), 0.1),
ease: "none",
onUpdate: function () {
- var time = tl.time();
-
- state.forEach(function (s) {
- var x = parseFloat(gsap.getProperty(s.el, "x")) || 0;
- var y = parseFloat(gsap.getProperty(s.el, "y")) || 0;
- var dt = time - s.prevTime;
-
- if (dt > 0.0005) {
- var vx = axis !== "y" ? (x - s.prevX) / dt : 0;
- var vy = axis !== "x" ? (y - s.prevY) / dt : 0;
-
- var bx = Math.min(Math.abs(vx) * blurScale, blurMax);
- var by = Math.min(Math.abs(vy) * blurScale, blurMax);
- var bxFinal = axis !== "y" ? bx : Math.max(by * 0.08, 0.4);
- var byFinal = axis !== "x" ? by : Math.max(bx * 0.08, 0.4);
- var active = bx > 0.3 || by > 0.3;
-
- if (active) {
- s.el.style.filter = "url(#" + s.filterId + ")";
- s.ghosts.forEach(function (g) {
- var dx = axis !== "y" ? (vx >= 0 ? -bxFinal * g.frac : bxFinal * g.frac) : 0;
- var dy = axis !== "x" ? (vy >= 0 ? -byFinal * g.frac : byFinal * g.frac) : 0;
- g.feOff.setAttribute("dx", dx.toFixed(2));
- g.feOff.setAttribute("dy", dy.toFixed(2));
- var gbx =
- axis !== "y"
- ? (bxFinal * g.frac * 0.5).toFixed(2)
- : Math.max(byFinal * g.frac * 0.04, 0.4).toFixed(2);
- var gby =
- axis !== "x"
- ? (byFinal * g.frac * 0.5).toFixed(2)
- : Math.max(bxFinal * g.frac * 0.04, 0.4).toFixed(2);
- g.feGB.setAttribute("stdDeviation", gbx + " " + gby);
- });
- s.feTopBlur.setAttribute(
- "stdDeviation",
- (bxFinal * 0.15).toFixed(2) + " " + (byFinal * 0.15).toFixed(2),
- );
-
- if (stretchMax > 0) {
- var sx = 1 + Math.min(Math.abs(vx) * stretchScale, stretchMax);
- var sy = 1 + Math.min(Math.abs(vy) * stretchScale, stretchMax);
- var ox = axis !== "y" ? (vx >= 0 ? "100% 50%" : "0% 50%") : "50% 50%";
- var oy = axis !== "x" ? (vy >= 0 ? "50% 100%" : "50% 0%") : "50% 50%";
- gsap.set(s.el, {
- scaleX: axis !== "y" ? sx : 1,
- scaleY: axis !== "x" ? sy : 1,
- transformOrigin: axis === "x" ? ox : axis === "y" ? oy : "50% 50%",
- });
- }
- } else {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- }
-
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- } else if (dt < -0.0005) {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- }
- // dt ≈ 0: double-fire — skip.
+ if (scheduled) return;
+ scheduled = true;
+ Promise.resolve().then(function () {
+ scheduled = false;
+ applyShutter();
});
},
},
@@ -273,7 +383,7 @@ That writes one file: `compositions/components/motion-blur.html`.
// Call AFTER tweens, BEFORE window.__timelines registration.
// attachMotionBlur adds a tracking tween with onUpdate — must be called after
// tl.set()/tl.to() have established the final timeline duration.
- attachMotionBlur("#my-box", tl, { axis: "x" });
+ attachMotionBlur("#my-box", tl, { shutterAngle: 720, samplesPerFrame: 16 });
window.__timelines = window.__timelines || {};
window.__timelines["my-composition"] = tl;
@@ -291,8 +401,9 @@ Paste the snippet into your composition, then call `attachMotionBlur()` after yo
tl.set(document.body, {}, DATA_DURATION);
attachMotionBlur("#my-box", tl, {
- axis: "x", // "x" | "y" | "both"
- blurMax: 40, // max blur radius in px (default 20)
+ shutterAngle: 720, // degrees of the frame interval the shutter is open
+ samplesPerFrame: 16, // sub-intervals of the window; 17 duplicates at 1/16 each
+ axis: "x", // "x" | "y" | "both"
});
window.__timelines = window.__timelines || {};
@@ -301,26 +412,30 @@ window.__timelines["my-composition"] = tl;
## How it works
-Each target element gets its own SVG filter. On every timeline seek, `attachMotionBlur` samples the element's GSAP `x`/`y` position, computes velocity, and drives three SVG filter primitives:
+This is the After Effects layer Motion Blur model — temporal supersampling — synthesised inside the page, because the renderer captures one instant per frame with no shutter.
+
+1. **Sample the trajectory** — after every timeline seek, the snippet seeks the timeline (events suppressed) to one sub-frame time per window boundary, reads each target's GSAP `x`/`y`, then restores the frame time. The window is `shutterAngle / 360 / fps` seconds long and starts `shutterPhase / 360 / fps` seconds from the frame time; `samplesPerFrame` divides it into that many sub-intervals, so there are `samplesPerFrame + 1` samples and both ends of the window carry one.
+2. **Add the duplicates** — each target gets an SVG filter that stacks one `feOffset` copy of the element per sample at its sampled position and adds them at equal weight (`feComposite` arithmetic, 1/N each, sRGB). A solid translating at speed `v` becomes a box smear of length `v × shutterTime`, centred on its instantaneous position — no one-sided trail and no Gaussian halo. No single duplicate exceeds `1/N`, so the tails step down evenly; where the element travels less than its own size the copies overlap past 1 and clamp, leaving the middle solid rather than a plateau.
+3. **Composite the sharp instance on top** — the element is then drawn over the smear at full opacity, so the position the frame is actually at stays crisp and only the duplicates are faint. This is the single largest difference from a plain average, and the one that makes the result read like After Effects rather than like a long exposure.
+4. **Rest is sharp** — when the sampled positions collapse onto the current one, the filter is removed.
-1. **Ghost copies** — three faded, blurred copies of the element placed behind it at increasing offsets proportional to speed. Inherently one-sided: no forward blur.
-2. **Top blur** — a small symmetric Gaussian at the current position so the element looks in-motion rather than crisp on top of the trail.
+The defaults come from measurement, not from the After Effects UI's nominal values. On a 1920×1080 / 30 fps export of translating text, the outermost duplicate on each side sits exactly one frame away from the frame time, with 8 evenly spaced duplicates between it and the centre — a 720° window at −360° phase, divided into 16. The staircase across a stroke steps by 0.063 ± 0.002 of the sharp text intensity per duplicate: flat 1/16, no taper toward the window edges. Replaying that export through this component scores 32.5 dB mean PSNR against it (min 27.6 over the 72 translating frames), against 24.2 dB (min 17.1) for the previous half-frame centred window.
-Blur scales linearly with velocity up to `blurMax`. Both the ghost trail and top blur clear automatically when the element decelerates to rest.
+Copies follow the real trajectory, so eased and curved motion smear correctly. The element's own scale and rotation are compensated when mapping the displacements into filter space; skew, 3D rotation and transformed ancestors are not. Only translation is integrated — rotation, scale or opacity changes within the shutter window are not blurred.
## Options
| Option | Default | Description |
| --- | --- | --- |
-| `axis` | `"both"` | Motion axis — `"x"`, `"y"`, or `"both"` |
-| `blurScale` | `0.008` | Blur per px/s of velocity |
-| `blurMax` | `20` | Max blur radius on the motion axis (px) |
-| `stretchScale` | `0.0002` | scaleX/Y added per px/s (requires `stretchMax > 0`) |
-| `stretchMax` | `0` | Max stretch above 1.0 — disabled by default |
+| `shutterAngle` | `720` | Degrees of the frame interval the shutter is open. `720` spans two frames, the width measured off the After Effects reference; `360` spans one; `0` disables the blur |
+| `shutterPhase` | `-360` | Degrees offset of the window start from the frame time. `-360` starts the window one frame back, which with a 720° angle centres it on the frame |
+| `samplesPerFrame` | `16` | Sub-intervals of the shutter window (2–64), so `N + 1` duplicates at `1/N` opacity each. More sub-intervals close the gaps between duplicates at high speed at a higher filter cost |
+| `fps` | root `data-fps`, else `30` | Composition frame rate. Pass it explicitly when rendering with an fps override (`hyperframes render --fps`) |
+| `axis` | `"both"` | Motion axis sampled — `"x"`, `"y"`, or `"both"` |
{/* hf:generated-footer */}
-Tagged `effect` `motion-blur` `velocity` `animation` `physics`.
+Tagged `effect` `motion-blur` `shutter` `after-effects` `velocity` `animation`.
## Related topics
diff --git a/docs/public/catalog-index.json b/docs/public/catalog-index.json
index 67a5e353e2..9bd94367e9 100644
--- a/docs/public/catalog-index.json
+++ b/docs/public/catalog-index.json
@@ -3340,13 +3340,14 @@
"name": "motion-blur",
"type": "component",
"title": "Motion Blur",
- "description": "Velocity-driven motion blur — samples element position each frame and applies a one-sided SVG feGaussianBlur ghost trail proportional to speed",
+ "description": "After Effects-style motion blur — integrates each element over a shutter window (shutter angle, phase, samples per frame) by sampling the GSAP timeline at sub-frame times and averaging equal-weight SVG copies along the real trajectory",
"tags": [
"effect",
"motion-blur",
+ "shutter",
+ "after-effects",
"velocity",
- "animation",
- "physics"
+ "animation"
],
"href": "/catalog/components/motion-blur",
"preview": "https://static.heygen.ai/hyperframes-oss/docs/images/catalog/components/motion-blur.png"
diff --git a/docs/public/catalog/components/motion-blur.json b/docs/public/catalog/components/motion-blur.json
index 07af3a41e4..5b36ba67b6 100644
--- a/docs/public/catalog/components/motion-blur.json
+++ b/docs/public/catalog/components/motion-blur.json
@@ -1 +1 @@
-{"html":"<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=1920, height=1080\" />\n <title>Motion Blur — Demo</title>\n <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js\"></script>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n html,\n body {\n margin: 0;\n width: 1920px;\n height: 1080px;\n overflow: hidden;\n background: #06060a;\n }\n\n #demo {\n position: relative;\n width: 1920px;\n height: 1080px;\n overflow: hidden;\n font-family: \"SF Mono\", ui-monospace, monospace;\n background: #06060a;\n }\n\n .header {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n height: 80px;\n display: flex;\n align-items: flex-end;\n padding: 0 72px 20px;\n border-bottom: 1px solid #0f0f18;\n }\n .header-title {\n font-size: 11px;\n letter-spacing: 0.4em;\n text-transform: uppercase;\n color: #1e1e2a;\n }\n .header-sub {\n margin-left: auto;\n font-size: 11px;\n letter-spacing: 0.25em;\n text-transform: uppercase;\n color: #14141c;\n }\n\n .group {\n position: absolute;\n left: 0;\n right: 0;\n height: 184px;\n }\n\n .group::after {\n content: \"\";\n position: absolute;\n bottom: 0;\n left: 72px;\n right: 72px;\n height: 1px;\n background: #0d0d15;\n }\n\n .dur {\n position: absolute;\n left: 72px;\n top: 0;\n width: 90px;\n height: 160px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n .dur-num {\n font-size: 28px;\n font-weight: 700;\n letter-spacing: -0.04em;\n color: #fff;\n line-height: 1;\n }\n .dur-unit {\n font-size: 9px;\n letter-spacing: 0.25em;\n text-transform: uppercase;\n color: #252532;\n margin-top: 5px;\n }\n\n .row-hint {\n position: absolute;\n left: 176px;\n width: 44px;\n height: 72px;\n display: flex;\n align-items: center;\n font-size: 8px;\n letter-spacing: 0.2em;\n text-transform: uppercase;\n color: #161620;\n }\n\n .spd {\n position: absolute;\n right: 72px;\n top: 0;\n width: 100px;\n height: 160px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: flex-end;\n }\n .spd-label {\n font-size: 10px;\n letter-spacing: 0.3em;\n text-transform: uppercase;\n color: #181822;\n }\n\n .pill {\n position: absolute;\n left: 0;\n top: 0;\n width: 200px;\n height: 72px;\n border-radius: 36px;\n /* Flat L1 ink: every row is the same object, so only the blur differs. */\n background: rgba(244, 244, 245, 0.72);\n will-change: transform, filter;\n }\n\n .word {\n position: absolute;\n left: 0;\n top: 88px;\n height: 72px;\n line-height: 72px;\n white-space: nowrap;\n font-size: 56px;\n font-weight: 800;\n letter-spacing: -0.03em;\n color: #f4f4f5;\n will-change: transform, filter;\n }\n\n .inner-div {\n position: absolute;\n left: 220px;\n right: 200px;\n top: 80px;\n height: 1px;\n background: #0a0a12;\n }\n\n .track-a,\n .track-b {\n position: absolute;\n left: 220px;\n right: 200px;\n height: 1px;\n background: #0c0c14;\n }\n .track-a {\n top: 35px;\n }\n .track-b {\n top: 123px;\n }\n </style>\n </head>\n <body>\n <div\n id=\"demo\"\n data-composition-id=\"motion-blur-demo\"\n data-width=\"1920\"\n data-height=\"1080\"\n data-start=\"0\"\n data-duration=\"4\"\n >\n <div class=\"header\">\n <span class=\"header-title\">Motion Blur — Velocity Showcase</span>\n <span class=\"header-sub\">feGaussianBlur + scaleX · blur ∝ velocity</span>\n </div>\n\n <div class=\"group\" style=\"top: 80px\">\n <div class=\"dur\"><span class=\"dur-num\">3.0</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s1\"></div>\n <div class=\"word\" id=\"t1\">DRIFT</div>\n <div class=\"spd\"><span class=\"spd-label\">slow</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 264px\">\n <div class=\"dur\"><span class=\"dur-num\">1.5</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s2\"></div>\n <div class=\"word\" id=\"t2\">GLIDE</div>\n <div class=\"spd\"><span class=\"spd-label\">medium</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 448px\">\n <div class=\"dur\"><span class=\"dur-num\">0.7</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s3\"></div>\n <div class=\"word\" id=\"t3\">RUSH</div>\n <div class=\"spd\"><span class=\"spd-label\">fast</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 632px\">\n <div class=\"dur\">\n <span class=\"dur-num\">0.35</span><span class=\"dur-unit\">seconds</span>\n </div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s4\"></div>\n <div class=\"word\" id=\"t4\">BLAST</div>\n <div class=\"spd\"><span class=\"spd-label\">faster</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 816px\">\n <div class=\"dur\"><span class=\"dur-num\">0.2</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s5\"></div>\n <div class=\"word\" id=\"t5\">WARP</div>\n <div class=\"spd\"><span class=\"spd-label\">extreme</span></div>\n </div>\n\n <script>\n (function () {\n if (!window._hfMbUid) window._hfMbUid = 0;\n var ns = \"http://www.w3.org/2000/svg\";\n\n window.attachMotionBlur = function (selector, tl, opts) {\n opts = opts || {};\n var blurScale = opts.blurScale !== undefined ? opts.blurScale : 0.008;\n var blurMax = opts.blurMax !== undefined ? opts.blurMax : 20;\n var stretchScale = opts.stretchScale !== undefined ? opts.stretchScale : 0.0002;\n var stretchMax = opts.stretchMax !== undefined ? opts.stretchMax : 0;\n var axis = opts.axis || \"both\";\n\n var items = Array.isArray(selector) ? selector : [selector];\n var targets = items.reduce(function (acc, s) {\n if (typeof s === \"string\") {\n document.querySelectorAll(s).forEach(function (el) {\n acc.push(el);\n });\n } else if (s instanceof Element) {\n acc.push(s);\n }\n return acc;\n }, []);\n\n var GHOST_CFG = [\n { frac: 0.25, slope: 0.55 },\n { frac: 0.55, slope: 0.28 },\n { frac: 1.0, slope: 0.1 },\n ];\n\n var state = targets.map(function (el) {\n var uid = \"hf-mb-\" + window._hfMbUid++;\n var svg = document.createElementNS(ns, \"svg\");\n svg.setAttribute(\"style\", \"position:absolute;width:0;height:0;overflow:hidden;\");\n\n var filter = document.createElementNS(ns, \"filter\");\n filter.id = uid;\n filter.setAttribute(\"x\", \"-110%\");\n filter.setAttribute(\"y\", \"-25%\");\n filter.setAttribute(\"width\", \"260%\");\n filter.setAttribute(\"height\", \"150%\");\n\n var ghosts = GHOST_CFG.map(function (cfg, gi) {\n var feOff = document.createElementNS(ns, \"feOffset\");\n feOff.setAttribute(\"in\", \"SourceGraphic\");\n feOff.setAttribute(\"dx\", \"0\");\n feOff.setAttribute(\"dy\", \"0\");\n feOff.setAttribute(\"result\", \"go\" + gi);\n\n var feGB = document.createElementNS(ns, \"feGaussianBlur\");\n feGB.setAttribute(\"in\", \"go\" + gi);\n feGB.setAttribute(\"stdDeviation\", \"0 0\");\n feGB.setAttribute(\"result\", \"gb\" + gi);\n\n var feCT = document.createElementNS(ns, \"feComponentTransfer\");\n feCT.setAttribute(\"in\", \"gb\" + gi);\n feCT.setAttribute(\"result\", \"gf\" + gi);\n var feFuncA = document.createElementNS(ns, \"feFuncA\");\n feFuncA.setAttribute(\"type\", \"linear\");\n feFuncA.setAttribute(\"slope\", String(cfg.slope));\n feCT.appendChild(feFuncA);\n\n filter.appendChild(feOff);\n filter.appendChild(feGB);\n filter.appendChild(feCT);\n return { feOff: feOff, feGB: feGB, frac: cfg.frac };\n });\n\n var feTopBlur = document.createElementNS(ns, \"feGaussianBlur\");\n feTopBlur.setAttribute(\"in\", \"SourceGraphic\");\n feTopBlur.setAttribute(\"stdDeviation\", \"0 0\");\n feTopBlur.setAttribute(\"result\", \"top\");\n filter.appendChild(feTopBlur);\n\n var feMerge = document.createElementNS(ns, \"feMerge\");\n for (var mi = GHOST_CFG.length - 1; mi >= 0; mi--) {\n var mn = document.createElementNS(ns, \"feMergeNode\");\n mn.setAttribute(\"in\", \"gf\" + mi);\n feMerge.appendChild(mn);\n }\n var mnTop = document.createElementNS(ns, \"feMergeNode\");\n mnTop.setAttribute(\"in\", \"top\");\n feMerge.appendChild(mnTop);\n filter.appendChild(feMerge);\n\n svg.appendChild(filter);\n document.body.appendChild(svg);\n\n return {\n el: el,\n ghosts: ghosts,\n feTopBlur: feTopBlur,\n filterId: uid,\n prevX: parseFloat(gsap.getProperty(el, \"x\")) || 0,\n prevY: parseFloat(gsap.getProperty(el, \"y\")) || 0,\n prevTime: tl.time(),\n };\n });\n\n var _proxy = { t: 0 };\n tl.to(\n _proxy,\n {\n t: 1,\n duration: Math.max(tl.duration(), 0.1),\n ease: \"none\",\n onUpdate: function () {\n var time = tl.time();\n\n state.forEach(function (s) {\n var x = parseFloat(gsap.getProperty(s.el, \"x\")) || 0;\n var y = parseFloat(gsap.getProperty(s.el, \"y\")) || 0;\n var dt = time - s.prevTime;\n\n if (dt > 0.0005) {\n var vx = axis !== \"y\" ? (x - s.prevX) / dt : 0;\n var vy = axis !== \"x\" ? (y - s.prevY) / dt : 0;\n\n var bx = Math.min(Math.abs(vx) * blurScale, blurMax);\n var by = Math.min(Math.abs(vy) * blurScale, blurMax);\n var bxFinal = axis !== \"y\" ? bx : Math.max(by * 0.08, 0.4);\n var byFinal = axis !== \"x\" ? by : Math.max(bx * 0.08, 0.4);\n var active = bx > 0.3 || by > 0.3;\n\n if (active) {\n s.el.style.filter = \"url(#\" + s.filterId + \")\";\n s.ghosts.forEach(function (g) {\n var dx =\n axis !== \"y\" ? (vx >= 0 ? -bxFinal * g.frac : bxFinal * g.frac) : 0;\n var dy =\n axis !== \"x\" ? (vy >= 0 ? -byFinal * g.frac : byFinal * g.frac) : 0;\n g.feOff.setAttribute(\"dx\", dx.toFixed(2));\n g.feOff.setAttribute(\"dy\", dy.toFixed(2));\n var gbx =\n axis !== \"y\"\n ? (bxFinal * g.frac * 0.5).toFixed(2)\n : Math.max(byFinal * g.frac * 0.04, 0.4).toFixed(2);\n var gby =\n axis !== \"x\"\n ? (byFinal * g.frac * 0.5).toFixed(2)\n : Math.max(bxFinal * g.frac * 0.04, 0.4).toFixed(2);\n g.feGB.setAttribute(\"stdDeviation\", gbx + \" \" + gby);\n });\n s.feTopBlur.setAttribute(\n \"stdDeviation\",\n (bxFinal * 0.15).toFixed(2) + \" \" + (byFinal * 0.15).toFixed(2),\n );\n if (stretchMax > 0) {\n var sx = 1 + Math.min(Math.abs(vx) * stretchScale, stretchMax);\n var sy = 1 + Math.min(Math.abs(vy) * stretchScale, stretchMax);\n var ox = axis !== \"y\" ? (vx >= 0 ? \"100% 50%\" : \"0% 50%\") : \"50% 50%\";\n var oy = axis !== \"x\" ? (vy >= 0 ? \"50% 100%\" : \"50% 0%\") : \"50% 50%\";\n gsap.set(s.el, {\n scaleX: axis !== \"y\" ? sx : 1,\n scaleY: axis !== \"x\" ? sy : 1,\n transformOrigin: axis === \"x\" ? ox : axis === \"y\" ? oy : \"50% 50%\",\n });\n }\n } else {\n s.el.style.filter = \"\";\n s.ghosts.forEach(function (g) {\n g.feOff.setAttribute(\"dx\", \"0\");\n g.feOff.setAttribute(\"dy\", \"0\");\n g.feGB.setAttribute(\"stdDeviation\", \"0 0\");\n });\n s.feTopBlur.setAttribute(\"stdDeviation\", \"0 0\");\n if (stretchMax > 0) {\n gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: \"50% 50%\" });\n }\n }\n\n s.prevX = x;\n s.prevY = y;\n s.prevTime = time;\n } else if (dt < -0.0005) {\n s.el.style.filter = \"\";\n s.ghosts.forEach(function (g) {\n g.feOff.setAttribute(\"dx\", \"0\");\n g.feOff.setAttribute(\"dy\", \"0\");\n g.feGB.setAttribute(\"stdDeviation\", \"0 0\");\n });\n s.feTopBlur.setAttribute(\"stdDeviation\", \"0 0\");\n if (stretchMax > 0) {\n gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: \"50% 50%\" });\n }\n s.prevX = x;\n s.prevY = y;\n s.prevTime = time;\n }\n // dt ≈ 0: double-fire — skip.\n });\n },\n },\n 0,\n );\n };\n\n var tl = gsap.timeline({ paused: true });\n\n gsap.set([\"#s1\", \"#s2\", \"#s3\", \"#s4\", \"#s5\", \"#t1\", \"#t2\", \"#t3\", \"#t4\", \"#t5\"], {\n x: -400,\n });\n\n tl.to([\"#s1\", \"#t1\"], { x: 1640, duration: 3.0, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s2\", \"#t2\"], { x: 1640, duration: 1.5, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s3\", \"#t3\"], { x: 1640, duration: 0.7, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s4\", \"#t4\"], { x: 1640, duration: 0.35, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s5\", \"#t5\"], { x: 1640, duration: 0.2, ease: \"power3.inOut\" }, 0);\n\n tl.set(document.body, {}, 4);\n\n attachMotionBlur(\n [\"#s1\", \"#s2\", \"#s3\", \"#s4\", \"#s5\", \"#t1\", \"#t2\", \"#t3\", \"#t4\", \"#t5\"],\n tl,\n { axis: \"x\", blurMax: 80, stretchMax: 0 },\n );\n\n window.__timelines = window.__timelines || {};\n window.__timelines[\"motion-blur-demo\"] = tl;\n })();\n </script>\n </div>\n </body>\n</html>\n"}
\ No newline at end of file
+{"html":"<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=1920, height=1080\" />\n <title>Motion Blur — Demo</title>\n <script src=\"https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js\"></script>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n html,\n body {\n margin: 0;\n width: 1920px;\n height: 1080px;\n overflow: hidden;\n background: #06060a;\n }\n\n #demo {\n position: relative;\n width: 1920px;\n height: 1080px;\n overflow: hidden;\n font-family: \"SF Mono\", ui-monospace, monospace;\n background: #06060a;\n }\n\n .header {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n height: 80px;\n display: flex;\n align-items: flex-end;\n padding: 0 72px 20px;\n border-bottom: 1px solid #0f0f18;\n }\n .header-title {\n font-size: 11px;\n letter-spacing: 0.4em;\n text-transform: uppercase;\n color: #1e1e2a;\n }\n .header-sub {\n margin-left: auto;\n font-size: 11px;\n letter-spacing: 0.25em;\n text-transform: uppercase;\n color: #14141c;\n }\n\n .group {\n position: absolute;\n left: 0;\n right: 0;\n height: 184px;\n }\n\n .group::after {\n content: \"\";\n position: absolute;\n bottom: 0;\n left: 72px;\n right: 72px;\n height: 1px;\n background: #0d0d15;\n }\n\n .dur {\n position: absolute;\n left: 72px;\n top: 0;\n width: 90px;\n height: 160px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n }\n .dur-num {\n font-size: 28px;\n font-weight: 700;\n letter-spacing: -0.04em;\n color: #fff;\n line-height: 1;\n }\n .dur-unit {\n font-size: 9px;\n letter-spacing: 0.25em;\n text-transform: uppercase;\n color: #252532;\n margin-top: 5px;\n }\n\n .row-hint {\n position: absolute;\n left: 176px;\n width: 44px;\n height: 72px;\n display: flex;\n align-items: center;\n font-size: 8px;\n letter-spacing: 0.2em;\n text-transform: uppercase;\n color: #161620;\n }\n\n .spd {\n position: absolute;\n right: 72px;\n top: 0;\n width: 100px;\n height: 160px;\n display: flex;\n flex-direction: column;\n justify-content: center;\n align-items: flex-end;\n }\n .spd-label {\n font-size: 10px;\n letter-spacing: 0.3em;\n text-transform: uppercase;\n color: #181822;\n }\n\n .pill {\n position: absolute;\n left: 0;\n top: 0;\n width: 200px;\n height: 72px;\n border-radius: 36px;\n /* Flat L1 ink: every row is the same object, so only the blur differs. */\n background: rgba(244, 244, 245, 0.72);\n will-change: transform, filter;\n }\n\n .word {\n position: absolute;\n left: 0;\n top: 88px;\n height: 72px;\n line-height: 72px;\n white-space: nowrap;\n font-size: 56px;\n font-weight: 800;\n letter-spacing: -0.03em;\n color: #f4f4f5;\n will-change: transform, filter;\n }\n\n .inner-div {\n position: absolute;\n left: 220px;\n right: 200px;\n top: 80px;\n height: 1px;\n background: #0a0a12;\n }\n\n .track-a,\n .track-b {\n position: absolute;\n left: 220px;\n right: 200px;\n height: 1px;\n background: #0c0c14;\n }\n .track-a {\n top: 35px;\n }\n .track-b {\n top: 123px;\n }\n </style>\n </head>\n <body>\n <div\n id=\"demo\"\n data-composition-id=\"motion-blur-demo\"\n data-width=\"1920\"\n data-height=\"1080\"\n data-start=\"0\"\n data-duration=\"4\"\n >\n <div class=\"header\">\n <span class=\"header-title\">Motion Blur — Velocity Showcase</span>\n <span class=\"header-sub\"\n >17 duplicates at 1/16 · 720° shutter · smear = speed × shutter time</span\n >\n </div>\n\n <div class=\"group\" style=\"top: 80px\">\n <div class=\"dur\"><span class=\"dur-num\">3.0</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s1\"></div>\n <div class=\"word\" id=\"t1\">DRIFT</div>\n <div class=\"spd\"><span class=\"spd-label\">slow</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 264px\">\n <div class=\"dur\"><span class=\"dur-num\">1.5</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s2\"></div>\n <div class=\"word\" id=\"t2\">GLIDE</div>\n <div class=\"spd\"><span class=\"spd-label\">medium</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 448px\">\n <div class=\"dur\"><span class=\"dur-num\">0.7</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s3\"></div>\n <div class=\"word\" id=\"t3\">RUSH</div>\n <div class=\"spd\"><span class=\"spd-label\">fast</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 632px\">\n <div class=\"dur\">\n <span class=\"dur-num\">0.35</span><span class=\"dur-unit\">seconds</span>\n </div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s4\"></div>\n <div class=\"word\" id=\"t4\">BLAST</div>\n <div class=\"spd\"><span class=\"spd-label\">faster</span></div>\n </div>\n\n <div class=\"group\" style=\"top: 816px\">\n <div class=\"dur\"><span class=\"dur-num\">0.2</span><span class=\"dur-unit\">seconds</span></div>\n <div class=\"row-hint\" style=\"top: 0\">shape</div>\n <div class=\"row-hint\" style=\"top: 88px\">text</div>\n <div class=\"track-a\"></div>\n <div class=\"inner-div\"></div>\n <div class=\"track-b\"></div>\n <div class=\"pill\" id=\"s5\"></div>\n <div class=\"word\" id=\"t5\">WARP</div>\n <div class=\"spd\"><span class=\"spd-label\">extreme</span></div>\n </div>\n\n <script>\n (function () {\n if (!window._hfMbUid) window._hfMbUid = 0;\n\n // Shutter length is measured in frames, so the snippet must know the\n // composition frame rate: explicit option, else the root's data-fps, else 30.\n function resolveFps(optionFps) {\n var explicit = Number(optionFps);\n if (explicit > 0) return explicit;\n\n var root = document.querySelector(\"[data-composition-id][data-fps]\");\n var rootFps = root ? Number(root.getAttribute(\"data-fps\")) : 0;\n if (rootFps > 0) return rootFps;\n\n return 30;\n }\n\n function numOption(value, fallback) {\n return value !== undefined ? Number(value) : fallback;\n }\n\n // objectBoundingBox percentage for a px offset plus padding.\n function regionPercent(offset, size, padPercent) {\n return ((offset / size) * 100 + padPercent).toFixed(2) + \"%\";\n }\n\n window.attachMotionBlur = function (selector, tl, opts) {\n opts = opts || {};\n var shutterAngle = numOption(opts.shutterAngle, 720);\n var shutterPhase = numOption(opts.shutterPhase, -360);\n var requestedSamples = numOption(opts.samplesPerFrame, 16);\n var samples = Number.isFinite(requestedSamples)\n ? Math.max(2, Math.min(64, Math.round(requestedSamples)))\n : 16;\n var axis = opts.axis || \"both\";\n var fps = resolveFps(opts.fps);\n var useX = axis !== \"y\";\n var useY = axis !== \"x\";\n\n // Untransformed box size; SVG elements have no offsetWidth, so use the\n // same bbox GSAP uses to resolve their percent transforms.\n function boxSize(el, horizontal) {\n var box = typeof el.offsetWidth === \"number\" ? el : el.getBBox ? el.getBBox() : null;\n var size = box\n ? horizontal\n ? box.offsetWidth || box.width\n : box.offsetHeight || box.height\n : 0;\n return size || el.getBoundingClientRect()[horizontal ? \"width\" : \"height\"] || 1;\n }\n\n // GSAP x/y may carry a % unit and xPercent/yPercent is a separate term;\n // resolve both against the element's own box so samples are in px.\n function readAxis(el, prop, percentProp, size) {\n var px = parseFloat(gsap.getProperty(el, prop, \"px\")) || 0;\n var percent = parseFloat(gsap.getProperty(el, percentProp)) || 0;\n return px + (percent * size) / 100;\n }\n\n function readPosition(el) {\n return {\n x: useX ? readAxis(el, \"x\", \"xPercent\", boxSize(el, true)) : 0,\n y: useY ? readAxis(el, \"y\", \"yPercent\", boxSize(el, false)) : 0,\n };\n }\n\n // CSS filters run in the element's pre-transform space while GSAP x/y are\n // post-transform, so a displacement is mapped through the inverse of the\n // element's own scale/rotation. Ancestor transforms are not compensated.\n function toFilterSpace(el, dx, dy) {\n var sx = parseFloat(gsap.getProperty(el, \"scaleX\")) || 1;\n var sy = parseFloat(gsap.getProperty(el, \"scaleY\")) || 1;\n var theta = ((parseFloat(gsap.getProperty(el, \"rotation\")) || 0) * Math.PI) / 180;\n var cos = Math.cos(theta);\n var sin = Math.sin(theta);\n return { dx: (dx * cos + dy * sin) / sx, dy: (-dx * sin + dy * cos) / sy };\n }\n\n var items = Array.isArray(selector) ? selector : [selector];\n var targets = items.reduce(function (acc, s) {\n if (typeof s === \"string\") {\n document.querySelectorAll(s).forEach(function (el) {\n acc.push(el);\n });\n } else if (s instanceof Element) {\n acc.push(s);\n }\n return acc;\n }, []);\n\n var ns = \"http://www.w3.org/2000/svg\";\n // `samples` counts sub-intervals of the shutter window, so there is one copy at\n // every interval boundary — both ends of the window included — and each carries\n // 1/samples of the source. That is what the reference export shows: the outermost\n // copy sits exactly one frame away from the frame time, not half a step short.\n var copies = samples + 1;\n var weight = String(1 / samples);\n\n // One SVG filter per target: N+1 offset copies of SourceGraphic added at 1/N\n // each, then the element itself over the top. Accumulating in sRGB matches\n // AE's default (non-linear) 8-bpc working space.\n var state = targets.map(function (el) {\n var uid = \"hf-mb-\" + window._hfMbUid++;\n var svg = document.createElementNS(ns, \"svg\");\n svg.setAttribute(\"style\", \"position:absolute;width:0;height:0;overflow:hidden;\");\n\n var filter = document.createElementNS(ns, \"filter\");\n filter.id = uid;\n filter.setAttribute(\"color-interpolation-filters\", \"sRGB\");\n\n var offsets = [];\n for (var k = 0; k < copies; k++) {\n var feOff = document.createElementNS(ns, \"feOffset\");\n feOff.setAttribute(\"in\", \"SourceGraphic\");\n feOff.setAttribute(\"dx\", \"0\");\n feOff.setAttribute(\"dy\", \"0\");\n feOff.setAttribute(\"result\", \"s\" + k);\n filter.appendChild(feOff);\n offsets.push(feOff);\n }\n\n // Pairwise accumulation: the first composite scales both inputs by 1/N, every\n // later one adds the next copy at 1/N to the running sum. The N+1 weights total\n // (N+1)/N, so an element wider than its own smear saturates through the middle\n // and the filter clamps there. That is the saturation the reference shows, and\n // the sharp instance covers the same region regardless.\n var accumulated = \"s0\";\n for (var c = 1; c < copies; c++) {\n var feComp = document.createElementNS(ns, \"feComposite\");\n feComp.setAttribute(\"operator\", \"arithmetic\");\n feComp.setAttribute(\"in\", accumulated);\n feComp.setAttribute(\"in2\", \"s\" + c);\n feComp.setAttribute(\"k1\", \"0\");\n feComp.setAttribute(\"k2\", c === 1 ? weight : \"1\");\n feComp.setAttribute(\"k3\", weight);\n feComp.setAttribute(\"k4\", \"0\");\n accumulated = \"a\" + c;\n feComp.setAttribute(\"result\", accumulated);\n filter.appendChild(feComp);\n }\n\n // The frame-time instance is drawn sharp, at full opacity, over the smear.\n // Every blurred copy stays at 1/N, so nothing but the instance the frame is\n // actually at reads as solid. Unnamed, so it is the filter output.\n var feOver = document.createElementNS(ns, \"feComposite\");\n feOver.setAttribute(\"operator\", \"over\");\n feOver.setAttribute(\"in\", \"SourceGraphic\");\n feOver.setAttribute(\"in2\", accumulated);\n filter.appendChild(feOver);\n\n svg.appendChild(filter);\n document.body.appendChild(svg);\n\n return { el: el, offsets: offsets, filter: filter, filterId: uid, xs: [], ys: [] };\n });\n\n // The element may carry its own inline filter (authored or tweened by\n // GSAP); the blur is appended to that chain and removed from it, never\n // written over it.\n var OWN_FILTER = /\\s*url\\([\"']?#hf-mb-\\d+[\"']?\\)/g;\n\n function baseFilter(el) {\n return el.style.filter.replace(OWN_FILTER, \"\").trim();\n }\n\n function clearBlur(s) {\n s.el.style.filter = baseFilter(s.el);\n }\n\n var scheduled = false;\n\n function applyShutter() {\n var shutterTime = shutterAngle / 360 / fps;\n if (!(shutterTime > 0)) {\n state.forEach(clearBlur);\n return;\n }\n\n var t0 = tl.time();\n var duration = tl.duration();\n var windowStart = t0 + shutterPhase / 360 / fps;\n\n // Sample the real trajectory: seek to each sub-frame time with events\n // suppressed (so no tween callbacks, including this tracker's, fire),\n // read positions, then restore the frame time.\n try {\n for (var k = 0; k < copies; k++) {\n var tk = windowStart + (k / samples) * shutterTime;\n tl.time(Math.min(duration, Math.max(0, tk)), true);\n state.forEach(function (s) {\n var pos = readPosition(s.el);\n s.xs[k] = pos.x;\n s.ys[k] = pos.y;\n });\n }\n } finally {\n tl.time(t0, true);\n }\n\n state.forEach(function (s) {\n var current = readPosition(s.el);\n var minDx = Infinity;\n var maxDx = -Infinity;\n var minDy = Infinity;\n var maxDy = -Infinity;\n for (var i = 0; i < copies; i++) {\n var d = toFilterSpace(s.el, s.xs[i] - current.x, s.ys[i] - current.y);\n var dx = d.dx;\n var dy = d.dy;\n s.offsets[i].setAttribute(\"dx\", dx.toFixed(3));\n s.offsets[i].setAttribute(\"dy\", dy.toFixed(3));\n if (dx < minDx) minDx = dx;\n if (dx > maxDx) maxDx = dx;\n if (dy < minDy) minDy = dy;\n if (dy > maxDy) maxDy = dy;\n }\n\n // Below half a pixel of smear the average is indistinguishable from\n // the source — render sharp instead of paying for the filter.\n if (maxDx - minDx < 0.5 && maxDy - minDy < 0.5) {\n clearBlur(s);\n return;\n }\n\n // Grow the filter region to cover every copy (objectBoundingBox\n // units, 10% padding so anti-aliased edges are not clipped).\n var w = boxSize(s.el, true);\n var h = boxSize(s.el, false);\n s.filter.setAttribute(\"x\", regionPercent(minDx, w, -10));\n s.filter.setAttribute(\"width\", regionPercent(maxDx - minDx, w, 120));\n s.filter.setAttribute(\"y\", regionPercent(minDy, h, -10));\n s.filter.setAttribute(\"height\", regionPercent(maxDy - minDy, h, 120));\n var base = baseFilter(s.el);\n s.el.style.filter = (base ? base + \" \" : \"\") + \"url(#\" + s.filterId + \")\";\n });\n }\n\n // tl.eventCallback(\"onUpdate\") is unavailable under the HyperFrames runtime proxy, so a\n // tracker tween's onUpdate fires on every seek. Sampling is deferred to a microtask:\n // seeking GSAP from inside its own render reads stale tween state, while the microtask\n // runs after the seek returns and before the frame is captured or painted.\n var _proxy = { t: 0 };\n tl.to(\n _proxy,\n {\n t: 1,\n duration: Math.max(tl.duration(), 0.1),\n ease: \"none\",\n onUpdate: function () {\n if (scheduled) return;\n scheduled = true;\n Promise.resolve().then(function () {\n scheduled = false;\n applyShutter();\n });\n },\n },\n 0,\n );\n };\n\n var tl = gsap.timeline({ paused: true });\n\n gsap.set([\"#s1\", \"#s2\", \"#s3\", \"#s4\", \"#s5\", \"#t1\", \"#t2\", \"#t3\", \"#t4\", \"#t5\"], {\n x: -400,\n });\n\n tl.to([\"#s1\", \"#t1\"], { x: 1640, duration: 3.0, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s2\", \"#t2\"], { x: 1640, duration: 1.5, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s3\", \"#t3\"], { x: 1640, duration: 0.7, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s4\", \"#t4\"], { x: 1640, duration: 0.35, ease: \"power3.inOut\" }, 0);\n tl.to([\"#s5\", \"#t5\"], { x: 1640, duration: 0.2, ease: \"power3.inOut\" }, 0);\n\n tl.set(document.body, {}, 4);\n\n attachMotionBlur(\n [\"#s1\", \"#s2\", \"#s3\", \"#s4\", \"#s5\", \"#t1\", \"#t2\", \"#t3\", \"#t4\", \"#t5\"],\n tl,\n { axis: \"x\" },\n );\n\n window.__timelines = window.__timelines || {};\n window.__timelines[\"motion-blur-demo\"] = tl;\n })();\n </script>\n </div>\n </body>\n</html>\n"}
\ No newline at end of file
diff --git a/packages/cli/src/registry/__fixtures__/motion-blur-ae-reference.json b/packages/cli/src/registry/__fixtures__/motion-blur-ae-reference.json
new file mode 100644
index 0000000000..c84f9ab000
--- /dev/null
+++ b/packages/cli/src/registry/__fixtures__/motion-blur-ae-reference.json
@@ -0,0 +1,17 @@
+{
+ "source": "After Effects export, 1920x1080, 30 fps, bold text translating along x, no other transforms",
+ "howMeasured": "Frame 5 of the export. The frame-time instance renders sharp at full opacity, so the ink > 0.97 bounding box tracks the word exactly; the duplicates show up as a staircase of plateaus across a vertical stroke. Rows 470 / 540 / 600 agree.",
+ "frame": 5,
+ "trailingDisplacementPx": 125.8,
+ "leadingDisplacementPx": 184.9,
+ "comment:displacements": "Core-centre travel from frame 4 to 5 and from 5 to 6. Measured ghost reach past the core is 128 px trailing and 189 px leading (both include the anti-aliased edge), i.e. the window ends land on the neighbouring frames' positions.",
+ "trailingCopyEdgesPx": [531, 546, 562, 578, 594, 609, 625, 640],
+ "sharpEdgePx": 656,
+ "comment:edges": "Rising edges of the leading stroke's duplicates on the trailing tail, row 470, outermost first; the sharp instance's edge closes the run. Mean spacing 15.6 px against a 125.8 px frame displacement = 1/8 frame per duplicate.",
+ "subIntervalsPerWindow": 16,
+ "windowFramesBefore": 1,
+ "windowFramesAfter": 1,
+ "copyOpacity": 0.0625,
+ "measuredPlateauIncrements": [0.063, 0.065, 0.063, 0.063, 0.063],
+ "comment:opacity": "Plateau heights across the trailing staircase, as a fraction of the sharp text intensity: 0.07 0.13 0.20 0.26 0.32 0.38. Flat, not tapered toward the window edge, and no duplicate approaches full opacity."
+}
diff --git a/packages/cli/src/registry/motionBlurShutter.browser.test.ts b/packages/cli/src/registry/motionBlurShutter.browser.test.ts
new file mode 100644
index 0000000000..b018fad042
--- /dev/null
+++ b/packages/cli/src/registry/motionBlurShutter.browser.test.ts
@@ -0,0 +1,247 @@
+// @vitest-environment happy-dom
+import { readFileSync } from "node:fs";
+import { dirname, resolve } from "node:path";
+import { fileURLToPath } from "node:url";
+import { afterEach, describe, expect, it } from "vitest";
+import reference from "./__fixtures__/motion-blur-ae-reference.json";
+
+const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../../../..");
+
+function readRepoFile(relativePath: string): string {
+ return readFileSync(resolve(repoRoot, relativePath), "utf8");
+}
+
+const snippetHtml = readRepoFile("registry/components/motion-blur/motion-blur.html");
+
+/** First line of the snippet's IIFE body, which runs to the `};` closing it at the same indent. */
+const BODY_FIRST_LINE = "if (!window._hfMbUid) window._hfMbUid = 0;";
+const SNIPPET_INDENT = " ".repeat(4);
+const INLINED_INDENT = " ".repeat(10);
+
+/**
+ * The snippet's IIFE body, leading whitespace dropped so the installable snippet and its inlined
+ * copies compare regardless of how deeply each one nests it.
+ */
+function snippetBody(source: string, indent: string): string {
+ const start = source.indexOf(indent + BODY_FIRST_LINE);
+ const endMarker = `\n${indent}};`;
+ const end = source.indexOf(endMarker, start);
+ if (start < 0 || end < 0) {
+ throw new Error(`could not locate the snippet body at indent ${indent.length}`);
+ }
+ return source
+ .slice(start, end + endMarker.length)
+ .split("\n")
+ .map((line) => line.trimStart())
+ .join("\n");
+}
+
+const FPS = 30;
+/** Timeline time of the frame under test, and a duration long enough that no seek is clamped. */
+const FRAME_TIME_S = 5;
+const DURATION_S = 10;
+const WORD_WIDTH = 1046;
+const WORD_HEIGHT = 193;
+
+/** The slice of GSAP's timeline API the snippet drives; `time()` reads, `time(value)` seeks. */
+interface Timeline {
+ time(value?: number, suppressEvents?: boolean): number | Timeline;
+ duration(): number;
+ to(target: unknown, vars: { onUpdate?: () => void }): Timeline;
+}
+
+/**
+ * The reference's own trajectory around the measured frame: a parabola through the core centres of
+ * frames 4, 5 and 6, with frame 5 at t = 0. Offsets are relative to the frame-time position, so the
+ * shutter window's ends must land on exactly the trailing and leading displacements the fixture
+ * records — which is the whole claim being pinned.
+ */
+function offsetAtFrames(df: number): number {
+ const back = -reference.trailingDisplacementPx;
+ const fwd = reference.leadingDisplacementPx;
+ return ((fwd + back) / 2) * df * df + ((fwd - back) / 2) * df;
+}
+
+function installSnippet(): void {
+ const body = snippetHtml.slice(
+ snippetHtml.indexOf("<script>") + "<script>".length,
+ snippetHtml.indexOf("</script>"),
+ );
+ new Function(body)();
+}
+
+function makeTimeline(): { tl: Timeline; currentTime: () => number; fire: () => void } {
+ let now = FRAME_TIME_S;
+ let onUpdate: (() => void) | undefined;
+ const tl: Timeline = {
+ time(value?: number) {
+ if (value === undefined) return now;
+ now = value;
+ return tl;
+ },
+ duration: () => DURATION_S,
+ to(_target, vars) {
+ onUpdate = vars.onUpdate;
+ return tl;
+ },
+ };
+ return { tl, currentTime: () => now, fire: () => onUpdate?.() };
+}
+
+function installGsap(currentTime: () => number, trajectory: (df: number) => number): void {
+ (globalThis as unknown as { gsap: unknown }).gsap = {
+ getProperty(_el: Element, prop: string) {
+ if (prop === "x") return `${trajectory((currentTime() - FRAME_TIME_S) * FPS)}px`;
+ if (prop === "scaleX" || prop === "scaleY") return 1;
+ return 0;
+ },
+ };
+}
+
+async function attach(
+ options: Record<string, unknown>,
+ trajectory: (df: number) => number = offsetAtFrames,
+): Promise<Element> {
+ const el = document.createElement("div");
+ el.id = "word";
+ Object.defineProperty(el, "offsetWidth", { value: WORD_WIDTH });
+ Object.defineProperty(el, "offsetHeight", { value: WORD_HEIGHT });
+ document.body.appendChild(el);
+
+ const { tl, currentTime, fire } = makeTimeline();
+ installGsap(currentTime, trajectory);
+ installSnippet();
+ (
+ window as unknown as { attachMotionBlur: (s: string, t: Timeline, o: unknown) => void }
+ ).attachMotionBlur("#word", tl, options);
+
+ fire();
+ await Promise.resolve();
+ const filter = document.querySelector("filter");
+ if (!filter) throw new Error("motion-blur filter was not created");
+ return filter;
+}
+
+/** Horizontal offset of every duplicate, in window order. */
+function copyOffsets(filter: Element): number[] {
+ return [...filter.querySelectorAll("feOffset")].map((node) => Number(node.getAttribute("dx")));
+}
+
+/** The duplicates sitting at the two ends of the shutter window. */
+function windowEdges(offsets: number[]): { trailing: number; leading: number } {
+ const [trailing] = offsets;
+ const leading = offsets.at(-1);
+ if (trailing === undefined || leading === undefined) {
+ throw new Error("the filter carries no duplicates");
+ }
+ return { trailing, leading };
+}
+
+/** Gap between each pair of neighbouring duplicates. */
+function copyPitches(offsets: number[]): number[] {
+ const pitches: number[] = [];
+ offsets.forEach((offset, index) => {
+ const previous = offsets[index - 1];
+ if (previous !== undefined) pitches.push(offset - previous);
+ });
+ return pitches;
+}
+
+afterEach(() => {
+ document.body.innerHTML = "";
+});
+
+describe("motion-blur snippet copies", () => {
+ // The demo and the example composition have to inline the snippet — a catalog demo is a single
+ // self-contained file and cannot import one. That makes three copies of the same shutter model, so
+ // the copies are asserted equal here rather than left to drift silently.
+ it.each([
+ "registry/components/motion-blur/demo.html",
+ "registry/examples/motion-blur/index.html",
+ ])("%s inlines the installable snippet verbatim", (relativePath) => {
+ expect(snippetBody(readRepoFile(relativePath), INLINED_INDENT)).toBe(
+ snippetBody(snippetHtml, SNIPPET_INDENT),
+ );
+ });
+});
+
+describe("motion-blur shutter matches the After Effects reference", () => {
+ it("opens the shutter over the frame before and the frame after, at the measured sub-interval count", async () => {
+ const offsets = copyOffsets(await attach({ fps: FPS }));
+ const { trailing, leading } = windowEdges(offsets);
+
+ expect(offsets).toHaveLength(reference.subIntervalsPerWindow + 1);
+ expect(trailing).toBeCloseTo(-reference.trailingDisplacementPx, 1);
+ expect(leading).toBeCloseTo(reference.leadingDisplacementPx, 1);
+ });
+
+ it("spaces the duplicates at the measured staircase pitch", async () => {
+ // The reference's staircase is even (15, 16, 16, 15, 16, 16, 16 px across a 125.8 px frame
+ // displacement), so a constant-velocity trajectory has to come out evenly spaced at 1/8 frame.
+ const speed = reference.trailingDisplacementPx;
+ const offsets = copyOffsets(await attach({ fps: FPS }, (df) => speed * df));
+ const expected = speed / (reference.subIntervalsPerWindow / 2);
+
+ for (const pitch of copyPitches(offsets)) expect(pitch).toBeCloseTo(expected, 3);
+ });
+
+ it("gives every duplicate the measured 1/16 opacity and none full opacity", async () => {
+ const filter = await attach({ fps: FPS });
+ const weights = [...filter.querySelectorAll("feComposite[operator='arithmetic']")].map((node) =>
+ Number(node.getAttribute("k3")),
+ );
+
+ expect(weights).toHaveLength(reference.subIntervalsPerWindow);
+ for (const weight of weights) expect(weight).toBeCloseTo(reference.copyOpacity, 6);
+ // Flat, not tapered: the reference's plateau increments are all the same height.
+ expect(new Set(weights).size).toBe(1);
+ });
+
+ it("accumulates every duplicate exactly once, in one unbroken chain", async () => {
+ const filter = await attach({ fps: FPS });
+ const adds = [...filter.querySelectorAll("feComposite[operator='arithmetic']")];
+ const weight = 1 / reference.subIntervalsPerWindow;
+
+ // The first composite is the only one that has to scale BOTH inputs, because it is the
+ // only one whose `in` is a raw duplicate rather than the running sum. Getting its k2
+ // wrong lets one duplicate through at full weight — the exact thing the reference rules out.
+ expect(adds[0]?.getAttribute("in")).toBe("s0");
+ expect(Number(adds[0]?.getAttribute("k2"))).toBeCloseTo(weight, 6);
+ for (const add of adds.slice(1)) expect(Number(add.getAttribute("k2"))).toBe(1);
+
+ // Each composite must fold in the next duplicate and feed the one after it, so every
+ // duplicate reaches the output and none is added twice.
+ adds.forEach((add, index) => {
+ expect(add.getAttribute("in")).toBe(index === 0 ? "s0" : `a${index}`);
+ expect(add.getAttribute("in2")).toBe(`s${index + 1}`);
+ expect(add.getAttribute("result")).toBe(`a${index + 1}`);
+ });
+ });
+
+ it("composites the sharp frame-time instance over the full accumulated smear", async () => {
+ const filter = await attach({ fps: FPS });
+ const last = filter.lastElementChild;
+
+ expect(last?.tagName).toBe("feComposite");
+ expect(last?.getAttribute("operator")).toBe("over");
+ expect(last?.getAttribute("in")).toBe("SourceGraphic");
+ // in2 must be the END of the accumulation chain, not some intermediate or single copy.
+ expect(last?.getAttribute("in2")).toBe(`a${reference.subIntervalsPerWindow}`);
+ expect(last?.getAttribute("result")).toBeNull();
+ });
+
+ it("keeps the sharp instance inside the filter region when the window is entirely one-sided", async () => {
+ // shutterPhase 0 opens the shutter at the frame time, so every duplicate is ahead of the
+ // element and no duplicate sits at offset 0 — but the sharp instance still does. A region
+ // derived from the duplicates alone starts inside the element's own box and clips it.
+ const filter = await attach({ fps: FPS, shutterPhase: 360 });
+ const offsets = copyOffsets(filter);
+
+ expect(Math.min(...offsets)).toBeGreaterThan(0);
+ expect(Number.parseFloat(filter.getAttribute("x") ?? "")).toBeLessThanOrEqual(0);
+ const right =
+ Number.parseFloat(filter.getAttribute("x") ?? "") +
+ Number.parseFloat(filter.getAttribute("width") ?? "");
+ expect(right).toBeGreaterThanOrEqual((Math.max(...offsets) / WORD_WIDTH) * 100 + 100);
+ });
+});
diff --git a/registry/catalog-artifact/local-vectors.bin b/registry/catalog-artifact/local-vectors.bin
index 1e98adde12..ec9f5af791 100644
Binary files a/registry/catalog-artifact/local-vectors.bin and b/registry/catalog-artifact/local-vectors.bin differ
diff --git a/registry/catalog-artifact/local-vectors.json b/registry/catalog-artifact/local-vectors.json
index 7448b71401..e27e5bbfed 100644
--- a/registry/catalog-artifact/local-vectors.json
+++ b/registry/catalog-artifact/local-vectors.json
@@ -2,7 +2,7 @@
"model": "bge-small-en-v1.5",
"modelRevision": "ea104dacec62c0de699686887e3f920caeb4f3e3",
"dimensions": 384,
- "revision": "b33b552d4f830abfcccb2bfe9495ac6284a7e7c05b3d3f4df630dfd5e753e518",
+ "revision": "34370735fa1a93099519873178e547c43b14f3bd69491013577515f4bb4f5957",
"names": [
"ai-chat-reveal",
"animated-bar-chart",
diff --git a/registry/components/motion-blur/demo.html b/registry/components/motion-blur/demo.html
index c058cca068..f2aae8d062 100644
--- a/registry/components/motion-blur/demo.html
+++ b/registry/components/motion-blur/demo.html
@@ -189,7 +189,9 @@
>
<div class="header">
<span class="header-title">Motion Blur — Velocity Showcase</span>
- <span class="header-sub">feGaussianBlur + scaleX · blur ∝ velocity</span>
+ <span class="header-sub"
+ >17 duplicates at 1/16 · 720° shutter · smear = speed × shutter time</span
+ >
</div>
<div class="group" style="top: 80px">
@@ -257,15 +259,80 @@
<script>
(function () {
if (!window._hfMbUid) window._hfMbUid = 0;
- var ns = "http://www.w3.org/2000/svg";
+
+ // Shutter length is measured in frames, so the snippet must know the
+ // composition frame rate: explicit option, else the root's data-fps, else 30.
+ function resolveFps(optionFps) {
+ var explicit = Number(optionFps);
+ if (explicit > 0) return explicit;
+
+ var root = document.querySelector("[data-composition-id][data-fps]");
+ var rootFps = root ? Number(root.getAttribute("data-fps")) : 0;
+ if (rootFps > 0) return rootFps;
+
+ return 30;
+ }
+
+ function numOption(value, fallback) {
+ return value !== undefined ? Number(value) : fallback;
+ }
+
+ // objectBoundingBox percentage for a px offset plus padding.
+ function regionPercent(offset, size, padPercent) {
+ return ((offset / size) * 100 + padPercent).toFixed(2) + "%";
+ }
window.attachMotionBlur = function (selector, tl, opts) {
opts = opts || {};
- var blurScale = opts.blurScale !== undefined ? opts.blurScale : 0.008;
- var blurMax = opts.blurMax !== undefined ? opts.blurMax : 20;
- var stretchScale = opts.stretchScale !== undefined ? opts.stretchScale : 0.0002;
- var stretchMax = opts.stretchMax !== undefined ? opts.stretchMax : 0;
+ var shutterAngle = numOption(opts.shutterAngle, 720);
+ var shutterPhase = numOption(opts.shutterPhase, -360);
+ var requestedSamples = numOption(opts.samplesPerFrame, 16);
+ var samples = Number.isFinite(requestedSamples)
+ ? Math.max(2, Math.min(64, Math.round(requestedSamples)))
+ : 16;
var axis = opts.axis || "both";
+ var fps = resolveFps(opts.fps);
+ var useX = axis !== "y";
+ var useY = axis !== "x";
+
+ // Untransformed box size; SVG elements have no offsetWidth, so use the
+ // same bbox GSAP uses to resolve their percent transforms.
+ function boxSize(el, horizontal) {
+ var box = typeof el.offsetWidth === "number" ? el : el.getBBox ? el.getBBox() : null;
+ var size = box
+ ? horizontal
+ ? box.offsetWidth || box.width
+ : box.offsetHeight || box.height
+ : 0;
+ return size || el.getBoundingClientRect()[horizontal ? "width" : "height"] || 1;
+ }
+
+ // GSAP x/y may carry a % unit and xPercent/yPercent is a separate term;
+ // resolve both against the element's own box so samples are in px.
+ function readAxis(el, prop, percentProp, size) {
+ var px = parseFloat(gsap.getProperty(el, prop, "px")) || 0;
+ var percent = parseFloat(gsap.getProperty(el, percentProp)) || 0;
+ return px + (percent * size) / 100;
+ }
+
+ function readPosition(el) {
+ return {
+ x: useX ? readAxis(el, "x", "xPercent", boxSize(el, true)) : 0,
+ y: useY ? readAxis(el, "y", "yPercent", boxSize(el, false)) : 0,
+ };
+ }
+
+ // CSS filters run in the element's pre-transform space while GSAP x/y are
+ // post-transform, so a displacement is mapped through the inverse of the
+ // element's own scale/rotation. Ancestor transforms are not compensated.
+ function toFilterSpace(el, dx, dy) {
+ var sx = parseFloat(gsap.getProperty(el, "scaleX")) || 1;
+ var sy = parseFloat(gsap.getProperty(el, "scaleY")) || 1;
+ var theta = ((parseFloat(gsap.getProperty(el, "rotation")) || 0) * Math.PI) / 180;
+ var cos = Math.cos(theta);
+ var sin = Math.sin(theta);
+ return { dx: (dx * cos + dy * sin) / sx, dy: (-dx * sin + dy * cos) / sy };
+ }
var items = Array.isArray(selector) ? selector : [selector];
var targets = items.reduce(function (acc, s) {
@@ -279,12 +346,17 @@
return acc;
}, []);
- var GHOST_CFG = [
- { frac: 0.25, slope: 0.55 },
- { frac: 0.55, slope: 0.28 },
- { frac: 1.0, slope: 0.1 },
- ];
-
+ var ns = "http://www.w3.org/2000/svg";
+ // `samples` counts sub-intervals of the shutter window, so there is one copy at
+ // every interval boundary — both ends of the window included — and each carries
+ // 1/samples of the source. That is what the reference export shows: the outermost
+ // copy sits exactly one frame away from the frame time, not half a step short.
+ var copies = samples + 1;
+ var weight = String(1 / samples);
+
+ // One SVG filter per target: N+1 offset copies of SourceGraphic added at 1/N
+ // each, then the element itself over the top. Accumulating in sRGB matches
+ // AE's default (non-linear) 8-bpc working space.
var state = targets.map(function (el) {
var uid = "hf-mb-" + window._hfMbUid++;
var svg = document.createElementNS(ns, "svg");
@@ -292,68 +364,147 @@
var filter = document.createElementNS(ns, "filter");
filter.id = uid;
- filter.setAttribute("x", "-110%");
- filter.setAttribute("y", "-25%");
- filter.setAttribute("width", "260%");
- filter.setAttribute("height", "150%");
+ filter.setAttribute("color-interpolation-filters", "sRGB");
- var ghosts = GHOST_CFG.map(function (cfg, gi) {
+ var offsets = [];
+ for (var k = 0; k < copies; k++) {
var feOff = document.createElementNS(ns, "feOffset");
feOff.setAttribute("in", "SourceGraphic");
feOff.setAttribute("dx", "0");
feOff.setAttribute("dy", "0");
- feOff.setAttribute("result", "go" + gi);
-
- var feGB = document.createElementNS(ns, "feGaussianBlur");
- feGB.setAttribute("in", "go" + gi);
- feGB.setAttribute("stdDeviation", "0 0");
- feGB.setAttribute("result", "gb" + gi);
-
- var feCT = document.createElementNS(ns, "feComponentTransfer");
- feCT.setAttribute("in", "gb" + gi);
- feCT.setAttribute("result", "gf" + gi);
- var feFuncA = document.createElementNS(ns, "feFuncA");
- feFuncA.setAttribute("type", "linear");
- feFuncA.setAttribute("slope", String(cfg.slope));
- feCT.appendChild(feFuncA);
-
+ feOff.setAttribute("result", "s" + k);
filter.appendChild(feOff);
- filter.appendChild(feGB);
- filter.appendChild(feCT);
- return { feOff: feOff, feGB: feGB, frac: cfg.frac };
- });
+ offsets.push(feOff);
+ }
- var feTopBlur = document.createElementNS(ns, "feGaussianBlur");
- feTopBlur.setAttribute("in", "SourceGraphic");
- feTopBlur.setAttribute("stdDeviation", "0 0");
- feTopBlur.setAttribute("result", "top");
- filter.appendChild(feTopBlur);
-
- var feMerge = document.createElementNS(ns, "feMerge");
- for (var mi = GHOST_CFG.length - 1; mi >= 0; mi--) {
- var mn = document.createElementNS(ns, "feMergeNode");
- mn.setAttribute("in", "gf" + mi);
- feMerge.appendChild(mn);
+ // Pairwise accumulation: the first composite scales both inputs by 1/N, every
+ // later one adds the next copy at 1/N to the running sum. The N+1 weights total
+ // (N+1)/N, so an element wider than its own smear saturates through the middle
+ // and the filter clamps there. That is the saturation the reference shows, and
+ // the sharp instance covers the same region regardless.
+ var accumulated = "s0";
+ for (var c = 1; c < copies; c++) {
+ var feComp = document.createElementNS(ns, "feComposite");
+ feComp.setAttribute("operator", "arithmetic");
+ feComp.setAttribute("in", accumulated);
+ feComp.setAttribute("in2", "s" + c);
+ feComp.setAttribute("k1", "0");
+ feComp.setAttribute("k2", c === 1 ? weight : "1");
+ feComp.setAttribute("k3", weight);
+ feComp.setAttribute("k4", "0");
+ accumulated = "a" + c;
+ feComp.setAttribute("result", accumulated);
+ filter.appendChild(feComp);
}
- var mnTop = document.createElementNS(ns, "feMergeNode");
- mnTop.setAttribute("in", "top");
- feMerge.appendChild(mnTop);
- filter.appendChild(feMerge);
+
+ // The frame-time instance is drawn sharp, at full opacity, over the smear.
+ // Every blurred copy stays at 1/N, so nothing but the instance the frame is
+ // actually at reads as solid. Unnamed, so it is the filter output.
+ var feOver = document.createElementNS(ns, "feComposite");
+ feOver.setAttribute("operator", "over");
+ feOver.setAttribute("in", "SourceGraphic");
+ feOver.setAttribute("in2", accumulated);
+ filter.appendChild(feOver);
svg.appendChild(filter);
document.body.appendChild(svg);
- return {
- el: el,
- ghosts: ghosts,
- feTopBlur: feTopBlur,
- filterId: uid,
- prevX: parseFloat(gsap.getProperty(el, "x")) || 0,
- prevY: parseFloat(gsap.getProperty(el, "y")) || 0,
- prevTime: tl.time(),
- };
+ return { el: el, offsets: offsets, filter: filter, filterId: uid, xs: [], ys: [] };
});
+ // The element may carry its own inline filter (authored or tweened by
+ // GSAP); the blur is appended to that chain and removed from it, never
+ // written over it.
+ var OWN_FILTER = /\s*url\(["']?#hf-mb-\d+["']?\)/g;
+
+ function baseFilter(el) {
+ return el.style.filter.replace(OWN_FILTER, "").trim();
+ }
+
+ function clearBlur(s) {
+ s.el.style.filter = baseFilter(s.el);
+ }
+
+ var scheduled = false;
+
+ function applyShutter() {
+ var shutterTime = shutterAngle / 360 / fps;
+ if (!(shutterTime > 0)) {
+ state.forEach(clearBlur);
+ return;
+ }
+
+ var t0 = tl.time();
+ var duration = tl.duration();
+ var windowStart = t0 + shutterPhase / 360 / fps;
+
+ // Sample the real trajectory: seek to each sub-frame time with events
+ // suppressed (so no tween callbacks, including this tracker's, fire),
+ // read positions, then restore the frame time.
+ try {
+ for (var k = 0; k < copies; k++) {
+ var tk = windowStart + (k / samples) * shutterTime;
+ tl.time(Math.min(duration, Math.max(0, tk)), true);
+ state.forEach(function (s) {
+ var pos = readPosition(s.el);
+ s.xs[k] = pos.x;
+ s.ys[k] = pos.y;
+ });
+ }
+ } finally {
+ tl.time(t0, true);
+ }
+
+ state.forEach(function (s) {
+ var current = readPosition(s.el);
+ var minDx = Infinity;
+ var maxDx = -Infinity;
+ var minDy = Infinity;
+ var maxDy = -Infinity;
+ for (var i = 0; i < copies; i++) {
+ var d = toFilterSpace(s.el, s.xs[i] - current.x, s.ys[i] - current.y);
+ var dx = d.dx;
+ var dy = d.dy;
+ s.offsets[i].setAttribute("dx", dx.toFixed(3));
+ s.offsets[i].setAttribute("dy", dy.toFixed(3));
+ if (dx < minDx) minDx = dx;
+ if (dx > maxDx) maxDx = dx;
+ if (dy < minDy) minDy = dy;
+ if (dy > maxDy) maxDy = dy;
+ }
+
+ // Below half a pixel of smear the average is indistinguishable from
+ // the source — render sharp instead of paying for the filter.
+ if (maxDx - minDx < 0.5 && maxDy - minDy < 0.5) {
+ clearBlur(s);
+ return;
+ }
+
+ // Grow the filter region to cover every copy AND the sharp instance the
+ // final composite draws at offset 0 (objectBoundingBox units, 10% padding
+ // so anti-aliased edges are not clipped). Clamping the bounds through 0
+ // matters whenever the window sits entirely on one side of the frame time
+ // — any shutterPhase above 0 or below -shutterAngle — because then no copy
+ // is at 0 and a region derived from the copies alone cuts the instance off.
+ var x0 = Math.min(0, minDx);
+ var x1 = Math.max(0, maxDx);
+ var y0 = Math.min(0, minDy);
+ var y1 = Math.max(0, maxDy);
+ var w = boxSize(s.el, true);
+ var h = boxSize(s.el, false);
+ s.filter.setAttribute("x", regionPercent(x0, w, -10));
+ s.filter.setAttribute("width", regionPercent(x1 - x0, w, 120));
+ s.filter.setAttribute("y", regionPercent(y0, h, -10));
+ s.filter.setAttribute("height", regionPercent(y1 - y0, h, 120));
+ var base = baseFilter(s.el);
+ s.el.style.filter = (base ? base + " " : "") + "url(#" + s.filterId + ")";
+ });
+ }
+
+ // tl.eventCallback("onUpdate") is unavailable under the HyperFrames runtime proxy, so a
+ // tracker tween's onUpdate fires on every seek. Sampling is deferred to a microtask:
+ // seeking GSAP from inside its own render reads stale tween state, while the microtask
+ // runs after the seek returns and before the frame is captured or painted.
var _proxy = { t: 0 };
tl.to(
_proxy,
@@ -362,89 +513,11 @@
duration: Math.max(tl.duration(), 0.1),
ease: "none",
onUpdate: function () {
- var time = tl.time();
-
- state.forEach(function (s) {
- var x = parseFloat(gsap.getProperty(s.el, "x")) || 0;
- var y = parseFloat(gsap.getProperty(s.el, "y")) || 0;
- var dt = time - s.prevTime;
-
- if (dt > 0.0005) {
- var vx = axis !== "y" ? (x - s.prevX) / dt : 0;
- var vy = axis !== "x" ? (y - s.prevY) / dt : 0;
-
- var bx = Math.min(Math.abs(vx) * blurScale, blurMax);
- var by = Math.min(Math.abs(vy) * blurScale, blurMax);
- var bxFinal = axis !== "y" ? bx : Math.max(by * 0.08, 0.4);
- var byFinal = axis !== "x" ? by : Math.max(bx * 0.08, 0.4);
- var active = bx > 0.3 || by > 0.3;
-
- if (active) {
- s.el.style.filter = "url(#" + s.filterId + ")";
- s.ghosts.forEach(function (g) {
- var dx =
- axis !== "y" ? (vx >= 0 ? -bxFinal * g.frac : bxFinal * g.frac) : 0;
- var dy =
- axis !== "x" ? (vy >= 0 ? -byFinal * g.frac : byFinal * g.frac) : 0;
- g.feOff.setAttribute("dx", dx.toFixed(2));
- g.feOff.setAttribute("dy", dy.toFixed(2));
- var gbx =
- axis !== "y"
- ? (bxFinal * g.frac * 0.5).toFixed(2)
- : Math.max(byFinal * g.frac * 0.04, 0.4).toFixed(2);
- var gby =
- axis !== "x"
- ? (byFinal * g.frac * 0.5).toFixed(2)
- : Math.max(bxFinal * g.frac * 0.04, 0.4).toFixed(2);
- g.feGB.setAttribute("stdDeviation", gbx + " " + gby);
- });
- s.feTopBlur.setAttribute(
- "stdDeviation",
- (bxFinal * 0.15).toFixed(2) + " " + (byFinal * 0.15).toFixed(2),
- );
- if (stretchMax > 0) {
- var sx = 1 + Math.min(Math.abs(vx) * stretchScale, stretchMax);
- var sy = 1 + Math.min(Math.abs(vy) * stretchScale, stretchMax);
- var ox = axis !== "y" ? (vx >= 0 ? "100% 50%" : "0% 50%") : "50% 50%";
- var oy = axis !== "x" ? (vy >= 0 ? "50% 100%" : "50% 0%") : "50% 50%";
- gsap.set(s.el, {
- scaleX: axis !== "y" ? sx : 1,
- scaleY: axis !== "x" ? sy : 1,
- transformOrigin: axis === "x" ? ox : axis === "y" ? oy : "50% 50%",
- });
- }
- } else {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- }
-
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- } else if (dt < -0.0005) {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- }
- // dt ≈ 0: double-fire — skip.
+ if (scheduled) return;
+ scheduled = true;
+ Promise.resolve().then(function () {
+ scheduled = false;
+ applyShutter();
});
},
},
@@ -469,7 +542,7 @@
attachMotionBlur(
["#s1", "#s2", "#s3", "#s4", "#s5", "#t1", "#t2", "#t3", "#t4", "#t5"],
tl,
- { axis: "x", blurMax: 80, stretchMax: 0 },
+ { axis: "x" },
);
window.__timelines = window.__timelines || {};
diff --git a/registry/components/motion-blur/motion-blur.html b/registry/components/motion-blur/motion-blur.html
index 5dc5336ec3..3f16b1fbf4 100644
--- a/registry/components/motion-blur/motion-blur.html
+++ b/registry/components/motion-blur/motion-blur.html
@@ -1,48 +1,156 @@
<!--
- Motion Blur — velocity-driven directional motion blur.
+ Motion Blur — After Effects-style shutter-based motion blur.
Usage: paste this snippet into your composition, then call
attachMotionBlur() with any element animated by your GSAP timeline.
- The snippet hooks into the timeline's onUpdate callback, tracks the
- GSAP x/y position of each target frame-by-frame, and applies:
- 1. Ghost copies of the element at increasing backward offsets with
- decreasing opacity — inherently one-sided, no forward blur component.
- 2. A small Gaussian blur at the current position so the element looks
- in-motion (blurry) rather than sharp on top of the trail.
- 3. An optional scaleX/Y stretch in the direction of travel (off by
- default; enable via stretchMax > 0 if you want the effect).
-
- Both effects clear automatically when the element decelerates to rest.
+ How it works — the same model After Effects uses for the layer Motion Blur
+ switch (temporal supersampling), synthesised inside the page because the
+ renderer captures one instant per frame with no shutter:
+
+ 1. After every timeline update (each rendered frame), the snippet seeks
+ the timeline to `samplesPerFrame` sub-frame times spread evenly across
+ the shutter window, reads each target's GSAP x/y at every sample, then
+ restores the frame time. Seeks run with events suppressed, so no user
+ callbacks fire and the DOM ends up exactly where the frame left it.
+ 2. An SVG filter stacks one copy of the element per sample (feOffset to
+ the sampled position relative to the current one) and adds them at
+ equal weight (feComposite arithmetic, 1/N each, sRGB space). Result:
+ a box smear along the actual trajectory whose length is speed ×
+ shutter time, with no decaying one-sided trail. The tails — where
+ fewer copies overlap — step down evenly at 1/N per copy; wherever the
+ element travels less than its own size the copies pile up past 1 and
+ clamp, so the middle of the smear is solid rather than a plateau.
+ 3. The element itself is then composited over that smear, sharp and at
+ full opacity. No single duplicate ever exceeds 1/N, so a moving edge
+ resolves as a staircase of ghosts behind a solid frame-time instance.
+ 4. When the sampled positions collapse to the current one (element at
+ rest), the filter is removed so the element renders sharp.
+
+ Shutter window (AE semantics, per frame at time t, frame interval 1/fps):
+ shutterTime = shutterAngle / 360 / fps
+ windowStart = t + shutterPhase / 360 / fps
+ copy k = windowStart + k / N × shutterTime, k = 0..N (N+1 copies)
+ N counts sub-intervals, so both ends of the window carry a copy.
+ Defaults (shutterAngle 720, shutterPhase -360) integrate [t - 1/fps, t + 1/fps]:
+ a solid moving at 2000 px/s at 30 fps smears 133 px, centred on its position.
+
+ These defaults are measured, not assumed. On a 1920×1080 / 30 fps After Effects
+ export of translating text, the outermost duplicate on the trailing side sits
+ exactly at the previous frame's position and the outermost leading duplicate
+ exactly at the next frame's, with 8 evenly spaced duplicates in between on each
+ side (window = 2 frames = 720°, phase -360°, 16 sub-intervals). Reading the ghost
+ staircase across a stroke gives steps of 0.063 ± 0.002 of the sharp text
+ intensity — a flat 1/16 per duplicate, with no taper toward the window edges
+ (triangle weighting scores 1.6 dB worse against the same export). The sharp
+ instance on top is what keeps total ink above the unblurred frame's.
Requirements:
- - Elements must be animated via GSAP x/y (transform), not left/top.
- - Call attachMotionBlur() AFTER defining all tweens, before
- window.__timelines registration.
+ - Elements must be animated via GSAP x/y (transform), not left/top. The
+ element's own scale/rotation is compensated; skew, 3D rotation and
+ transformed ancestors are not.
+ - The host must render the timeline for the blur to update — HyperFrames
+ seeks every frame. A fresh paused timeline that is never seeked shows no
+ blur on its first frame.
+ - Call attachMotionBlur() AFTER defining all tweens (the timeline's final
+ duration must be known), before window.__timelines registration.
- GSAP must be loaded before this snippet executes.
API:
attachMotionBlur(selector, timeline, options?)
Options:
- blurScale — directional blur per px/s of velocity (default 0.008)
- blurMax — max blur radius on the motion axis in px (default 20)
- stretchScale — scaleX/Y added per px/s (default 0.0002)
- stretchMax — max stretch factor above 1.0 (default 0, disabled)
- axis — "x" | "y" | "both" (default "both")
+ shutterAngle — degrees of the frame interval the shutter is open
+ (default 720 = two frames, as measured off the AE
+ reference; 360 = one frame, 0 disables)
+ shutterPhase — degrees offset of the window start from the frame
+ time (default -360 = centred on the frame, one frame
+ back, like the AE reference)
+ samplesPerFrame — sub-intervals of the shutter window, so N+1 duplicates
+ each at 1/N opacity (default 16, max 64)
+ fps — composition frame rate (default: the root's data-fps,
+ else 30). Pass it explicitly when rendering with an
+ fps override (`hyperframes render --fps`).
+ axis — "x" | "y" | "both" (default "both")
-->
<script>
(function () {
if (!window._hfMbUid) window._hfMbUid = 0;
+ // Shutter length is measured in frames, so the snippet must know the
+ // composition frame rate: explicit option, else the root's data-fps, else 30.
+ function resolveFps(optionFps) {
+ var explicit = Number(optionFps);
+ if (explicit > 0) return explicit;
+
+ var root = document.querySelector("[data-composition-id][data-fps]");
+ var rootFps = root ? Number(root.getAttribute("data-fps")) : 0;
+ if (rootFps > 0) return rootFps;
+
+ return 30;
+ }
+
+ function numOption(value, fallback) {
+ return value !== undefined ? Number(value) : fallback;
+ }
+
+ // objectBoundingBox percentage for a px offset plus padding.
+ function regionPercent(offset, size, padPercent) {
+ return ((offset / size) * 100 + padPercent).toFixed(2) + "%";
+ }
+
window.attachMotionBlur = function (selector, tl, opts) {
opts = opts || {};
- var blurScale = opts.blurScale !== undefined ? opts.blurScale : 0.008;
- var blurMax = opts.blurMax !== undefined ? opts.blurMax : 20;
- var stretchScale = opts.stretchScale !== undefined ? opts.stretchScale : 0.0002;
- var stretchMax = opts.stretchMax !== undefined ? opts.stretchMax : 0;
+ var shutterAngle = numOption(opts.shutterAngle, 720);
+ var shutterPhase = numOption(opts.shutterPhase, -360);
+ var requestedSamples = numOption(opts.samplesPerFrame, 16);
+ var samples = Number.isFinite(requestedSamples)
+ ? Math.max(2, Math.min(64, Math.round(requestedSamples)))
+ : 16;
var axis = opts.axis || "both";
+ var fps = resolveFps(opts.fps);
+ var useX = axis !== "y";
+ var useY = axis !== "x";
+
+ // Untransformed box size; SVG elements have no offsetWidth, so use the
+ // same bbox GSAP uses to resolve their percent transforms.
+ function boxSize(el, horizontal) {
+ var box = typeof el.offsetWidth === "number" ? el : el.getBBox ? el.getBBox() : null;
+ var size = box
+ ? horizontal
+ ? box.offsetWidth || box.width
+ : box.offsetHeight || box.height
+ : 0;
+ return size || el.getBoundingClientRect()[horizontal ? "width" : "height"] || 1;
+ }
+
+ // GSAP x/y may carry a % unit and xPercent/yPercent is a separate term;
+ // resolve both against the element's own box so samples are in px.
+ function readAxis(el, prop, percentProp, size) {
+ var px = parseFloat(gsap.getProperty(el, prop, "px")) || 0;
+ var percent = parseFloat(gsap.getProperty(el, percentProp)) || 0;
+ return px + (percent * size) / 100;
+ }
+
+ function readPosition(el) {
+ return {
+ x: useX ? readAxis(el, "x", "xPercent", boxSize(el, true)) : 0,
+ y: useY ? readAxis(el, "y", "yPercent", boxSize(el, false)) : 0,
+ };
+ }
+
+ // CSS filters run in the element's pre-transform space while GSAP x/y are
+ // post-transform, so a displacement is mapped through the inverse of the
+ // element's own scale/rotation. Ancestor transforms are not compensated.
+ function toFilterSpace(el, dx, dy) {
+ var sx = parseFloat(gsap.getProperty(el, "scaleX")) || 1;
+ var sy = parseFloat(gsap.getProperty(el, "scaleY")) || 1;
+ var theta = ((parseFloat(gsap.getProperty(el, "rotation")) || 0) * Math.PI) / 180;
+ var cos = Math.cos(theta);
+ var sin = Math.sin(theta);
+ return { dx: (dx * cos + dy * sin) / sx, dy: (-dx * sin + dy * cos) / sy };
+ }
var items = Array.isArray(selector) ? selector : [selector];
var targets = items.reduce(function (acc, s) {
@@ -56,15 +164,17 @@
return acc;
}, []);
- // One SVG filter per target. Ghost copies placed behind → inherently one-sided.
- // Small top Gaussian makes element look blurry at current position, not sharp.
var ns = "http://www.w3.org/2000/svg";
- var GHOST_CFG = [
- { frac: 0.25, slope: 0.55 },
- { frac: 0.55, slope: 0.28 },
- { frac: 1.0, slope: 0.1 },
- ];
-
+ // `samples` counts sub-intervals of the shutter window, so there is one copy at
+ // every interval boundary — both ends of the window included — and each carries
+ // 1/samples of the source. That is what the reference export shows: the outermost
+ // copy sits exactly one frame away from the frame time, not half a step short.
+ var copies = samples + 1;
+ var weight = String(1 / samples);
+
+ // One SVG filter per target: N+1 offset copies of SourceGraphic added at 1/N
+ // each, then the element itself over the top. Accumulating in sRGB matches
+ // AE's default (non-linear) 8-bpc working space.
var state = targets.map(function (el) {
var uid = "hf-mb-" + window._hfMbUid++;
var svg = document.createElementNS(ns, "svg");
@@ -72,70 +182,147 @@
var filter = document.createElementNS(ns, "filter");
filter.id = uid;
- filter.setAttribute("x", "-110%");
- filter.setAttribute("y", "-25%");
- filter.setAttribute("width", "260%");
- filter.setAttribute("height", "150%");
+ filter.setAttribute("color-interpolation-filters", "sRGB");
- var ghosts = GHOST_CFG.map(function (cfg, gi) {
+ var offsets = [];
+ for (var k = 0; k < copies; k++) {
var feOff = document.createElementNS(ns, "feOffset");
feOff.setAttribute("in", "SourceGraphic");
feOff.setAttribute("dx", "0");
feOff.setAttribute("dy", "0");
- feOff.setAttribute("result", "go" + gi);
-
- var feGB = document.createElementNS(ns, "feGaussianBlur");
- feGB.setAttribute("in", "go" + gi);
- feGB.setAttribute("stdDeviation", "0 0");
- feGB.setAttribute("result", "gb" + gi);
-
- var feCT = document.createElementNS(ns, "feComponentTransfer");
- feCT.setAttribute("in", "gb" + gi);
- feCT.setAttribute("result", "gf" + gi);
- var feFuncA = document.createElementNS(ns, "feFuncA");
- feFuncA.setAttribute("type", "linear");
- feFuncA.setAttribute("slope", String(cfg.slope));
- feCT.appendChild(feFuncA);
-
+ feOff.setAttribute("result", "s" + k);
filter.appendChild(feOff);
- filter.appendChild(feGB);
- filter.appendChild(feCT);
- return { feOff: feOff, feGB: feGB, frac: cfg.frac };
- });
+ offsets.push(feOff);
+ }
- var feTopBlur = document.createElementNS(ns, "feGaussianBlur");
- feTopBlur.setAttribute("in", "SourceGraphic");
- feTopBlur.setAttribute("stdDeviation", "0 0");
- feTopBlur.setAttribute("result", "top");
- filter.appendChild(feTopBlur);
-
- var feMerge = document.createElementNS(ns, "feMerge");
- for (var mi = GHOST_CFG.length - 1; mi >= 0; mi--) {
- var mn = document.createElementNS(ns, "feMergeNode");
- mn.setAttribute("in", "gf" + mi);
- feMerge.appendChild(mn);
+ // Pairwise accumulation: the first composite scales both inputs by 1/N, every
+ // later one adds the next copy at 1/N to the running sum. The N+1 weights total
+ // (N+1)/N, so an element wider than its own smear saturates through the middle
+ // and the filter clamps there. That is the saturation the reference shows, and
+ // the sharp instance covers the same region regardless.
+ var accumulated = "s0";
+ for (var c = 1; c < copies; c++) {
+ var feComp = document.createElementNS(ns, "feComposite");
+ feComp.setAttribute("operator", "arithmetic");
+ feComp.setAttribute("in", accumulated);
+ feComp.setAttribute("in2", "s" + c);
+ feComp.setAttribute("k1", "0");
+ feComp.setAttribute("k2", c === 1 ? weight : "1");
+ feComp.setAttribute("k3", weight);
+ feComp.setAttribute("k4", "0");
+ accumulated = "a" + c;
+ feComp.setAttribute("result", accumulated);
+ filter.appendChild(feComp);
}
- var mnTop = document.createElementNS(ns, "feMergeNode");
- mnTop.setAttribute("in", "top");
- feMerge.appendChild(mnTop);
- filter.appendChild(feMerge);
+
+ // The frame-time instance is drawn sharp, at full opacity, over the smear.
+ // Every blurred copy stays at 1/N, so nothing but the instance the frame is
+ // actually at reads as solid. Unnamed, so it is the filter output.
+ var feOver = document.createElementNS(ns, "feComposite");
+ feOver.setAttribute("operator", "over");
+ feOver.setAttribute("in", "SourceGraphic");
+ feOver.setAttribute("in2", accumulated);
+ filter.appendChild(feOver);
svg.appendChild(filter);
document.body.appendChild(svg);
- return {
- el: el,
- ghosts: ghosts,
- feTopBlur: feTopBlur,
- filterId: uid,
- prevX: parseFloat(gsap.getProperty(el, "x")) || 0,
- prevY: parseFloat(gsap.getProperty(el, "y")) || 0,
- prevTime: tl.time(),
- };
+ return { el: el, offsets: offsets, filter: filter, filterId: uid, xs: [], ys: [] };
});
- // tl.eventCallback("onUpdate") is not available in the HyperFrames renderer —
- // the runtime proxies the timeline object. Tween onUpdate fires on every seek.
+ // The element may carry its own inline filter (authored or tweened by
+ // GSAP); the blur is appended to that chain and removed from it, never
+ // written over it.
+ var OWN_FILTER = /\s*url\(["']?#hf-mb-\d+["']?\)/g;
+
+ function baseFilter(el) {
+ return el.style.filter.replace(OWN_FILTER, "").trim();
+ }
+
+ function clearBlur(s) {
+ s.el.style.filter = baseFilter(s.el);
+ }
+
+ var scheduled = false;
+
+ function applyShutter() {
+ var shutterTime = shutterAngle / 360 / fps;
+ if (!(shutterTime > 0)) {
+ state.forEach(clearBlur);
+ return;
+ }
+
+ var t0 = tl.time();
+ var duration = tl.duration();
+ var windowStart = t0 + shutterPhase / 360 / fps;
+
+ // Sample the real trajectory: seek to each sub-frame time with events
+ // suppressed (so no tween callbacks, including this tracker's, fire),
+ // read positions, then restore the frame time.
+ try {
+ for (var k = 0; k < copies; k++) {
+ var tk = windowStart + (k / samples) * shutterTime;
+ tl.time(Math.min(duration, Math.max(0, tk)), true);
+ state.forEach(function (s) {
+ var pos = readPosition(s.el);
+ s.xs[k] = pos.x;
+ s.ys[k] = pos.y;
+ });
+ }
+ } finally {
+ tl.time(t0, true);
+ }
+
+ state.forEach(function (s) {
+ var current = readPosition(s.el);
+ var minDx = Infinity;
+ var maxDx = -Infinity;
+ var minDy = Infinity;
+ var maxDy = -Infinity;
+ for (var i = 0; i < copies; i++) {
+ var d = toFilterSpace(s.el, s.xs[i] - current.x, s.ys[i] - current.y);
+ var dx = d.dx;
+ var dy = d.dy;
+ s.offsets[i].setAttribute("dx", dx.toFixed(3));
+ s.offsets[i].setAttribute("dy", dy.toFixed(3));
+ if (dx < minDx) minDx = dx;
+ if (dx > maxDx) maxDx = dx;
+ if (dy < minDy) minDy = dy;
+ if (dy > maxDy) maxDy = dy;
+ }
+
+ // Below half a pixel of smear the average is indistinguishable from
+ // the source — render sharp instead of paying for the filter.
+ if (maxDx - minDx < 0.5 && maxDy - minDy < 0.5) {
+ clearBlur(s);
+ return;
+ }
+
+ // Grow the filter region to cover every copy AND the sharp instance the
+ // final composite draws at offset 0 (objectBoundingBox units, 10% padding
+ // so anti-aliased edges are not clipped). Clamping the bounds through 0
+ // matters whenever the window sits entirely on one side of the frame time
+ // — any shutterPhase above 0 or below -shutterAngle — because then no copy
+ // is at 0 and a region derived from the copies alone cuts the instance off.
+ var x0 = Math.min(0, minDx);
+ var x1 = Math.max(0, maxDx);
+ var y0 = Math.min(0, minDy);
+ var y1 = Math.max(0, maxDy);
+ var w = boxSize(s.el, true);
+ var h = boxSize(s.el, false);
+ s.filter.setAttribute("x", regionPercent(x0, w, -10));
+ s.filter.setAttribute("width", regionPercent(x1 - x0, w, 120));
+ s.filter.setAttribute("y", regionPercent(y0, h, -10));
+ s.filter.setAttribute("height", regionPercent(y1 - y0, h, 120));
+ var base = baseFilter(s.el);
+ s.el.style.filter = (base ? base + " " : "") + "url(#" + s.filterId + ")";
+ });
+ }
+
+ // tl.eventCallback("onUpdate") is unavailable under the HyperFrames runtime proxy, so a
+ // tracker tween's onUpdate fires on every seek. Sampling is deferred to a microtask:
+ // seeking GSAP from inside its own render reads stale tween state, while the microtask
+ // runs after the seek returns and before the frame is captured or painted.
var _proxy = { t: 0 };
tl.to(
_proxy,
@@ -144,88 +331,11 @@
duration: Math.max(tl.duration(), 0.1),
ease: "none",
onUpdate: function () {
- var time = tl.time();
-
- state.forEach(function (s) {
- var x = parseFloat(gsap.getProperty(s.el, "x")) || 0;
- var y = parseFloat(gsap.getProperty(s.el, "y")) || 0;
- var dt = time - s.prevTime;
-
- if (dt > 0.0005) {
- var vx = axis !== "y" ? (x - s.prevX) / dt : 0;
- var vy = axis !== "x" ? (y - s.prevY) / dt : 0;
-
- var bx = Math.min(Math.abs(vx) * blurScale, blurMax);
- var by = Math.min(Math.abs(vy) * blurScale, blurMax);
- var bxFinal = axis !== "y" ? bx : Math.max(by * 0.08, 0.4);
- var byFinal = axis !== "x" ? by : Math.max(bx * 0.08, 0.4);
- var active = bx > 0.3 || by > 0.3;
-
- if (active) {
- s.el.style.filter = "url(#" + s.filterId + ")";
- s.ghosts.forEach(function (g) {
- var dx = axis !== "y" ? (vx >= 0 ? -bxFinal * g.frac : bxFinal * g.frac) : 0;
- var dy = axis !== "x" ? (vy >= 0 ? -byFinal * g.frac : byFinal * g.frac) : 0;
- g.feOff.setAttribute("dx", dx.toFixed(2));
- g.feOff.setAttribute("dy", dy.toFixed(2));
- var gbx =
- axis !== "y"
- ? (bxFinal * g.frac * 0.5).toFixed(2)
- : Math.max(byFinal * g.frac * 0.04, 0.4).toFixed(2);
- var gby =
- axis !== "x"
- ? (byFinal * g.frac * 0.5).toFixed(2)
- : Math.max(bxFinal * g.frac * 0.04, 0.4).toFixed(2);
- g.feGB.setAttribute("stdDeviation", gbx + " " + gby);
- });
- s.feTopBlur.setAttribute(
- "stdDeviation",
- (bxFinal * 0.15).toFixed(2) + " " + (byFinal * 0.15).toFixed(2),
- );
-
- if (stretchMax > 0) {
- var sx = 1 + Math.min(Math.abs(vx) * stretchScale, stretchMax);
- var sy = 1 + Math.min(Math.abs(vy) * stretchScale, stretchMax);
- var ox = axis !== "y" ? (vx >= 0 ? "100% 50%" : "0% 50%") : "50% 50%";
- var oy = axis !== "x" ? (vy >= 0 ? "50% 100%" : "50% 0%") : "50% 50%";
- gsap.set(s.el, {
- scaleX: axis !== "y" ? sx : 1,
- scaleY: axis !== "x" ? sy : 1,
- transformOrigin: axis === "x" ? ox : axis === "y" ? oy : "50% 50%",
- });
- }
- } else {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- }
-
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- } else if (dt < -0.0005) {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- }
- // dt ≈ 0: double-fire — skip.
+ if (scheduled) return;
+ scheduled = true;
+ Promise.resolve().then(function () {
+ scheduled = false;
+ applyShutter();
});
},
},
@@ -248,7 +358,7 @@
// Call AFTER tweens, BEFORE window.__timelines registration.
// attachMotionBlur adds a tracking tween with onUpdate — must be called after
// tl.set()/tl.to() have established the final timeline duration.
- attachMotionBlur("#my-box", tl, { axis: "x" });
+ attachMotionBlur("#my-box", tl, { shutterAngle: 720, samplesPerFrame: 16 });
window.__timelines = window.__timelines || {};
window.__timelines["my-composition"] = tl;
diff --git a/registry/components/motion-blur/registry-item.json b/registry/components/motion-blur/registry-item.json
index ba73fe60a2..65f61b805f 100644
--- a/registry/components/motion-blur/registry-item.json
+++ b/registry/components/motion-blur/registry-item.json
@@ -3,8 +3,8 @@
"name": "motion-blur",
"type": "hyperframes:component",
"title": "Motion Blur",
- "description": "Velocity-driven motion blur — samples element position each frame and applies a one-sided SVG feGaussianBlur ghost trail proportional to speed",
- "tags": ["effect", "motion-blur", "velocity", "animation", "physics"],
+ "description": "After Effects-style motion blur — integrates each element over a shutter window (shutter angle, phase, samples per frame) by sampling the GSAP timeline at sub-frame times and averaging equal-weight SVG copies along the real trajectory",
+ "tags": ["effect", "motion-blur", "shutter", "after-effects", "velocity", "animation"],
"files": [
{
"path": "motion-blur.html",
diff --git a/registry/examples/motion-blur/index.html b/registry/examples/motion-blur/index.html
index 034cc42bf7..b97741bcc0 100644
--- a/registry/examples/motion-blur/index.html
+++ b/registry/examples/motion-blur/index.html
@@ -194,7 +194,9 @@
>
<div class="header" data-layout-ignore>
<span class="header-title">Motion Blur — Velocity Showcase</span>
- <span class="header-sub">feGaussianBlur + scaleX · blur ∝ velocity</span>
+ <span class="header-sub"
+ >17 duplicates at 1/16 · 720° shutter · smear = speed × shutter time</span
+ >
</div>
<!-- Group 1: 3.0s slow — top: 80 -->
@@ -341,15 +343,80 @@
(function () {
/* ── attachMotionBlur ─────────────────────────────────────── */
if (!window._hfMbUid) window._hfMbUid = 0;
- var ns = "http://www.w3.org/2000/svg";
- function attachMotionBlur(selector, tl, opts) {
+ // Shutter length is measured in frames, so the snippet must know the
+ // composition frame rate: explicit option, else the root's data-fps, else 30.
+ function resolveFps(optionFps) {
+ var explicit = Number(optionFps);
+ if (explicit > 0) return explicit;
+
+ var root = document.querySelector("[data-composition-id][data-fps]");
+ var rootFps = root ? Number(root.getAttribute("data-fps")) : 0;
+ if (rootFps > 0) return rootFps;
+
+ return 30;
+ }
+
+ function numOption(value, fallback) {
+ return value !== undefined ? Number(value) : fallback;
+ }
+
+ // objectBoundingBox percentage for a px offset plus padding.
+ function regionPercent(offset, size, padPercent) {
+ return ((offset / size) * 100 + padPercent).toFixed(2) + "%";
+ }
+
+ window.attachMotionBlur = function (selector, tl, opts) {
opts = opts || {};
- var blurScale = opts.blurScale !== undefined ? opts.blurScale : 0.008;
- var blurMax = opts.blurMax !== undefined ? opts.blurMax : 20;
- var stretchScale = opts.stretchScale !== undefined ? opts.stretchScale : 0.0002;
- var stretchMax = opts.stretchMax !== undefined ? opts.stretchMax : 0;
+ var shutterAngle = numOption(opts.shutterAngle, 720);
+ var shutterPhase = numOption(opts.shutterPhase, -360);
+ var requestedSamples = numOption(opts.samplesPerFrame, 16);
+ var samples = Number.isFinite(requestedSamples)
+ ? Math.max(2, Math.min(64, Math.round(requestedSamples)))
+ : 16;
var axis = opts.axis || "both";
+ var fps = resolveFps(opts.fps);
+ var useX = axis !== "y";
+ var useY = axis !== "x";
+
+ // Untransformed box size; SVG elements have no offsetWidth, so use the
+ // same bbox GSAP uses to resolve their percent transforms.
+ function boxSize(el, horizontal) {
+ var box = typeof el.offsetWidth === "number" ? el : el.getBBox ? el.getBBox() : null;
+ var size = box
+ ? horizontal
+ ? box.offsetWidth || box.width
+ : box.offsetHeight || box.height
+ : 0;
+ return size || el.getBoundingClientRect()[horizontal ? "width" : "height"] || 1;
+ }
+
+ // GSAP x/y may carry a % unit and xPercent/yPercent is a separate term;
+ // resolve both against the element's own box so samples are in px.
+ function readAxis(el, prop, percentProp, size) {
+ var px = parseFloat(gsap.getProperty(el, prop, "px")) || 0;
+ var percent = parseFloat(gsap.getProperty(el, percentProp)) || 0;
+ return px + (percent * size) / 100;
+ }
+
+ function readPosition(el) {
+ return {
+ x: useX ? readAxis(el, "x", "xPercent", boxSize(el, true)) : 0,
+ y: useY ? readAxis(el, "y", "yPercent", boxSize(el, false)) : 0,
+ };
+ }
+
+ // CSS filters run in the element's pre-transform space while GSAP x/y are
+ // post-transform, so a displacement is mapped through the inverse of the
+ // element's own scale/rotation. Ancestor transforms are not compensated.
+ function toFilterSpace(el, dx, dy) {
+ var sx = parseFloat(gsap.getProperty(el, "scaleX")) || 1;
+ var sy = parseFloat(gsap.getProperty(el, "scaleY")) || 1;
+ var theta = ((parseFloat(gsap.getProperty(el, "rotation")) || 0) * Math.PI) / 180;
+ var cos = Math.cos(theta);
+ var sin = Math.sin(theta);
+ return { dx: (dx * cos + dy * sin) / sx, dy: (-dx * sin + dy * cos) / sy };
+ }
var items = Array.isArray(selector) ? selector : [selector];
var targets = items.reduce(function (acc, s) {
@@ -363,14 +430,17 @@
return acc;
}, []);
- // Ghost trail: copies placed only behind the element → inherently one-sided.
- // Top layer: small Gaussian at current position so element looks blurry, not sharp.
- var GHOST_CFG = [
- { frac: 0.25, slope: 0.55 },
- { frac: 0.55, slope: 0.28 },
- { frac: 1.0, slope: 0.1 },
- ];
-
+ var ns = "http://www.w3.org/2000/svg";
+ // `samples` counts sub-intervals of the shutter window, so there is one copy at
+ // every interval boundary — both ends of the window included — and each carries
+ // 1/samples of the source. That is what the reference export shows: the outermost
+ // copy sits exactly one frame away from the frame time, not half a step short.
+ var copies = samples + 1;
+ var weight = String(1 / samples);
+
+ // One SVG filter per target: N+1 offset copies of SourceGraphic added at 1/N
+ // each, then the element itself over the top. Accumulating in sRGB matches
+ // AE's default (non-linear) 8-bpc working space.
var state = targets.map(function (el) {
var uid = "hf-mb-" + window._hfMbUid++;
var svg = document.createElementNS(ns, "svg");
@@ -378,70 +448,147 @@
var filter = document.createElementNS(ns, "filter");
filter.id = uid;
- filter.setAttribute("x", "-110%");
- filter.setAttribute("y", "-25%");
- filter.setAttribute("width", "260%");
- filter.setAttribute("height", "150%");
+ filter.setAttribute("color-interpolation-filters", "sRGB");
- var ghosts = GHOST_CFG.map(function (cfg, gi) {
+ var offsets = [];
+ for (var k = 0; k < copies; k++) {
var feOff = document.createElementNS(ns, "feOffset");
feOff.setAttribute("in", "SourceGraphic");
feOff.setAttribute("dx", "0");
feOff.setAttribute("dy", "0");
- feOff.setAttribute("result", "go" + gi);
-
- var feGB = document.createElementNS(ns, "feGaussianBlur");
- feGB.setAttribute("in", "go" + gi);
- feGB.setAttribute("stdDeviation", "0 0");
- feGB.setAttribute("result", "gb" + gi);
-
- var feCT = document.createElementNS(ns, "feComponentTransfer");
- feCT.setAttribute("in", "gb" + gi);
- feCT.setAttribute("result", "gf" + gi);
- var feFuncA = document.createElementNS(ns, "feFuncA");
- feFuncA.setAttribute("type", "linear");
- feFuncA.setAttribute("slope", String(cfg.slope));
- feCT.appendChild(feFuncA);
-
+ feOff.setAttribute("result", "s" + k);
filter.appendChild(feOff);
- filter.appendChild(feGB);
- filter.appendChild(feCT);
- return { feOff: feOff, feGB: feGB, frac: cfg.frac };
- });
+ offsets.push(feOff);
+ }
- var feTopBlur = document.createElementNS(ns, "feGaussianBlur");
- feTopBlur.setAttribute("in", "SourceGraphic");
- feTopBlur.setAttribute("stdDeviation", "0 0");
- feTopBlur.setAttribute("result", "top");
- filter.appendChild(feTopBlur);
-
- var feMerge = document.createElementNS(ns, "feMerge");
- for (var mi = GHOST_CFG.length - 1; mi >= 0; mi--) {
- var mn = document.createElementNS(ns, "feMergeNode");
- mn.setAttribute("in", "gf" + mi);
- feMerge.appendChild(mn);
+ // Pairwise accumulation: the first composite scales both inputs by 1/N, every
+ // later one adds the next copy at 1/N to the running sum. The N+1 weights total
+ // (N+1)/N, so an element wider than its own smear saturates through the middle
+ // and the filter clamps there. That is the saturation the reference shows, and
+ // the sharp instance covers the same region regardless.
+ var accumulated = "s0";
+ for (var c = 1; c < copies; c++) {
+ var feComp = document.createElementNS(ns, "feComposite");
+ feComp.setAttribute("operator", "arithmetic");
+ feComp.setAttribute("in", accumulated);
+ feComp.setAttribute("in2", "s" + c);
+ feComp.setAttribute("k1", "0");
+ feComp.setAttribute("k2", c === 1 ? weight : "1");
+ feComp.setAttribute("k3", weight);
+ feComp.setAttribute("k4", "0");
+ accumulated = "a" + c;
+ feComp.setAttribute("result", accumulated);
+ filter.appendChild(feComp);
}
- var mnTop = document.createElementNS(ns, "feMergeNode");
- mnTop.setAttribute("in", "top");
- feMerge.appendChild(mnTop);
- filter.appendChild(feMerge);
+
+ // The frame-time instance is drawn sharp, at full opacity, over the smear.
+ // Every blurred copy stays at 1/N, so nothing but the instance the frame is
+ // actually at reads as solid. Unnamed, so it is the filter output.
+ var feOver = document.createElementNS(ns, "feComposite");
+ feOver.setAttribute("operator", "over");
+ feOver.setAttribute("in", "SourceGraphic");
+ feOver.setAttribute("in2", accumulated);
+ filter.appendChild(feOver);
svg.appendChild(filter);
document.body.appendChild(svg);
- return {
- el: el,
- ghosts: ghosts,
- feTopBlur: feTopBlur,
- filterId: uid,
- prevX: parseFloat(gsap.getProperty(el, "x")) || 0,
- prevY: parseFloat(gsap.getProperty(el, "y")) || 0,
- prevTime: tl.time(),
- };
+ return { el: el, offsets: offsets, filter: filter, filterId: uid, xs: [], ys: [] };
});
- // tl.eventCallback("onUpdate") is not available in the HyperFrames renderer —
- // the runtime proxies the timeline. Tween onUpdate fires on every seek instead.
+ // The element may carry its own inline filter (authored or tweened by
+ // GSAP); the blur is appended to that chain and removed from it, never
+ // written over it.
+ var OWN_FILTER = /\s*url\(["']?#hf-mb-\d+["']?\)/g;
+
+ function baseFilter(el) {
+ return el.style.filter.replace(OWN_FILTER, "").trim();
+ }
+
+ function clearBlur(s) {
+ s.el.style.filter = baseFilter(s.el);
+ }
+
+ var scheduled = false;
+
+ function applyShutter() {
+ var shutterTime = shutterAngle / 360 / fps;
+ if (!(shutterTime > 0)) {
+ state.forEach(clearBlur);
+ return;
+ }
+
+ var t0 = tl.time();
+ var duration = tl.duration();
+ var windowStart = t0 + shutterPhase / 360 / fps;
+
+ // Sample the real trajectory: seek to each sub-frame time with events
+ // suppressed (so no tween callbacks, including this tracker's, fire),
+ // read positions, then restore the frame time.
+ try {
+ for (var k = 0; k < copies; k++) {
+ var tk = windowStart + (k / samples) * shutterTime;
+ tl.time(Math.min(duration, Math.max(0, tk)), true);
+ state.forEach(function (s) {
+ var pos = readPosition(s.el);
+ s.xs[k] = pos.x;
+ s.ys[k] = pos.y;
+ });
+ }
+ } finally {
+ tl.time(t0, true);
+ }
+
+ state.forEach(function (s) {
+ var current = readPosition(s.el);
+ var minDx = Infinity;
+ var maxDx = -Infinity;
+ var minDy = Infinity;
+ var maxDy = -Infinity;
+ for (var i = 0; i < copies; i++) {
+ var d = toFilterSpace(s.el, s.xs[i] - current.x, s.ys[i] - current.y);
+ var dx = d.dx;
+ var dy = d.dy;
+ s.offsets[i].setAttribute("dx", dx.toFixed(3));
+ s.offsets[i].setAttribute("dy", dy.toFixed(3));
+ if (dx < minDx) minDx = dx;
+ if (dx > maxDx) maxDx = dx;
+ if (dy < minDy) minDy = dy;
+ if (dy > maxDy) maxDy = dy;
+ }
+
+ // Below half a pixel of smear the average is indistinguishable from
+ // the source — render sharp instead of paying for the filter.
+ if (maxDx - minDx < 0.5 && maxDy - minDy < 0.5) {
+ clearBlur(s);
+ return;
+ }
+
+ // Grow the filter region to cover every copy AND the sharp instance the
+ // final composite draws at offset 0 (objectBoundingBox units, 10% padding
+ // so anti-aliased edges are not clipped). Clamping the bounds through 0
+ // matters whenever the window sits entirely on one side of the frame time
+ // — any shutterPhase above 0 or below -shutterAngle — because then no copy
+ // is at 0 and a region derived from the copies alone cuts the instance off.
+ var x0 = Math.min(0, minDx);
+ var x1 = Math.max(0, maxDx);
+ var y0 = Math.min(0, minDy);
+ var y1 = Math.max(0, maxDy);
+ var w = boxSize(s.el, true);
+ var h = boxSize(s.el, false);
+ s.filter.setAttribute("x", regionPercent(x0, w, -10));
+ s.filter.setAttribute("width", regionPercent(x1 - x0, w, 120));
+ s.filter.setAttribute("y", regionPercent(y0, h, -10));
+ s.filter.setAttribute("height", regionPercent(y1 - y0, h, 120));
+ var base = baseFilter(s.el);
+ s.el.style.filter = (base ? base + " " : "") + "url(#" + s.filterId + ")";
+ });
+ }
+
+ // tl.eventCallback("onUpdate") is unavailable under the HyperFrames runtime proxy, so a
+ // tracker tween's onUpdate fires on every seek. Sampling is deferred to a microtask:
+ // seeking GSAP from inside its own render reads stale tween state, while the microtask
+ // runs after the seek returns and before the frame is captured or painted.
var _proxy = { t: 0 };
tl.to(
_proxy,
@@ -450,95 +597,17 @@
duration: Math.max(tl.duration(), 0.1),
ease: "none",
onUpdate: function () {
- var time = tl.time();
-
- state.forEach(function (s) {
- var x = parseFloat(gsap.getProperty(s.el, "x")) || 0;
- var y = parseFloat(gsap.getProperty(s.el, "y")) || 0;
- var dt = time - s.prevTime;
-
- if (dt > 0.0005) {
- var vx = axis !== "y" ? (x - s.prevX) / dt : 0;
- var vy = axis !== "x" ? (y - s.prevY) / dt : 0;
-
- var bx = Math.min(Math.abs(vx) * blurScale, blurMax);
- var by = Math.min(Math.abs(vy) * blurScale, blurMax);
- var bxFinal = axis !== "y" ? bx : Math.max(by * 0.08, 0.4);
- var byFinal = axis !== "x" ? by : Math.max(bx * 0.08, 0.4);
- var active = bx > 0.3 || by > 0.3;
-
- if (active) {
- s.el.style.filter = "url(#" + s.filterId + ")";
- s.ghosts.forEach(function (g) {
- var dx =
- axis !== "y" ? (vx >= 0 ? -bxFinal * g.frac : bxFinal * g.frac) : 0;
- var dy =
- axis !== "x" ? (vy >= 0 ? -byFinal * g.frac : byFinal * g.frac) : 0;
- g.feOff.setAttribute("dx", dx.toFixed(2));
- g.feOff.setAttribute("dy", dy.toFixed(2));
- var gbx =
- axis !== "y"
- ? (bxFinal * g.frac * 0.5).toFixed(2)
- : Math.max(byFinal * g.frac * 0.04, 0.4).toFixed(2);
- var gby =
- axis !== "x"
- ? (byFinal * g.frac * 0.5).toFixed(2)
- : Math.max(bxFinal * g.frac * 0.04, 0.4).toFixed(2);
- g.feGB.setAttribute("stdDeviation", gbx + " " + gby);
- });
- s.feTopBlur.setAttribute(
- "stdDeviation",
- (bxFinal * 0.15).toFixed(2) + " " + (byFinal * 0.15).toFixed(2),
- );
- if (stretchMax > 0) {
- var sx = 1 + Math.min(Math.abs(vx) * stretchScale, stretchMax);
- var sy = 1 + Math.min(Math.abs(vy) * stretchScale, stretchMax);
- var ox = axis !== "y" ? (vx >= 0 ? "100% 50%" : "0% 50%") : "50% 50%";
- var oy = axis !== "x" ? (vy >= 0 ? "50% 100%" : "50% 0%") : "50% 50%";
- gsap.set(s.el, {
- scaleX: axis !== "y" ? sx : 1,
- scaleY: axis !== "x" ? sy : 1,
- transformOrigin: axis === "x" ? ox : axis === "y" ? oy : "50% 50%",
- });
- }
- } else {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- }
-
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- } else if (dt < -0.0005) {
- s.el.style.filter = "";
- s.ghosts.forEach(function (g) {
- g.feOff.setAttribute("dx", "0");
- g.feOff.setAttribute("dy", "0");
- g.feGB.setAttribute("stdDeviation", "0 0");
- });
- s.feTopBlur.setAttribute("stdDeviation", "0 0");
- if (stretchMax > 0) {
- gsap.set(s.el, { scaleX: 1, scaleY: 1, transformOrigin: "50% 50%" });
- }
- s.prevX = x;
- s.prevY = y;
- s.prevTime = time;
- }
- // dt ≈ 0: runtime double-fires — skip.
+ if (scheduled) return;
+ scheduled = true;
+ Promise.resolve().then(function () {
+ scheduled = false;
+ applyShutter();
});
},
},
0,
);
- }
+ };
/* ── Timeline ─────────────────────────────────────────────── */
var tl = gsap.timeline({ paused: true });
@@ -560,7 +629,7 @@
attachMotionBlur(
["#s1", "#s2", "#s3", "#s4", "#s5", "#t1", "#t2", "#t3", "#t4", "#t5"],
tl,
- { axis: "x", blurMax: 80, stretchMax: 0 },
+ { axis: "x" },
);
window.__timelines = window.__timelines || {};
diff --git a/registry/registry.json b/registry/registry.json
index f833eead35..79044ea9f9 100644
--- a/registry/registry.json
+++ b/registry/registry.json
@@ -1637,6 +1637,6 @@
}
],
"catalogArtifact": {
- "revision": "b33b552d4f830abfcccb2bfe9495ac6284a7e7c05b3d3f4df630dfd5e753e518"
+ "revision": "34370735fa1a93099519873178e547c43b14f3bd69491013577515f4bb4f5957"
}
}