Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
feat(registry): gooey split block with metaball goo and directional motion blur (#5123)
Miguel Ángelb50dead1da59
diff --git a/packages/cli/src/registry/motionBlurShutter.browser.test.ts b/packages/cli/src/registry/motionBlurShutter.browser.test.tsindex fef71d3558..e0dd1d2873 100644--- a/packages/cli/src/registry/motionBlurShutter.browser.test.ts+++ b/packages/cli/src/registry/motionBlurShutter.browser.test.ts@@ -116,6 +116,14 @@ function makeTimeline(onTo?: () => void): Fake {return { tl, currentTime: () => now, fire: () => onUpdate?.(), trackers: () => trackers };}+/** What the browser resolves for the target: an inline !important, else the marker's rule, else the inline value. */+function wordVisibility(word: Element): string {+ const style = (word as HTMLElement).style;+ if (style.getPropertyPriority("visibility") === "important") return style.visibility;+ if (word.hasAttribute(HIDING)) return "hidden";+ return style.visibility || "visible";+}+/*** happy-dom resolves no transforms of its own, so the element's computed style is the trajectory.* The stub also answers the declaration enumeration the style replay uses, and the perspective.@@ -135,6 +143,7 @@ function installComputedStyle(transformOrigin: "50% 50%",opacity: element === word ? opacity() : "1",perspective: element === word ? "none" : perspective(),+ visibility: element === word ? wordVisibility(word) : "visible",}) as unknown as CSSStyleDeclaration) as typeof globalThis.getComputedStyle;}@@ -232,6 +241,8 @@ function copyPitches(offsets: number[]): number[] {}const originalGetComputedStyle = globalThis.getComputedStyle;+/** The marker sharp 0 sets on a moving target; a stylesheet rule does the hiding. */+const HIDING = "data-hf-motion-blur-hiding";beforeEach(() => {// The snippet polls the registry on a timer for seconds. Fake timers let a test reach the@@ -255,12 +266,13 @@ afterEach(async () => {describe("motion-blur snippet copies", () => {// The demos and the example composition have to inline the snippet — a catalog plate is a single- // self-contained file and cannot import one. That makes four copies of the same shutter model, so+ // self-contained file and cannot import one. That makes five 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/components/shutter-slam/shutter-slam.html","registry/components/shutter-slam/demo.html",+ "registry/blocks/gooey-split/gooey-split.html",])("%s inlines the installable snippet verbatim", (relativePath) => {expect(snippetBody(readRepoFile(relativePath))).toBe(snippetBody(snippetHtml));});@@ -314,6 +326,87 @@ describe("motion-blur shutter matches the After Effects reference", () => {// group has to precede the element rather than follow it.expect(group.nextElementSibling).toBe(word);expect(word.style.opacity).toBe("");+ expect(word.hasAttribute(HIDING)).toBe(false);+ expect(word.style.visibility).toBe("");+ });++ it("leaves only the shutter average while moving at sharp 0, and the element at rest", async () => {+ let speed = 1;+ const { group, word, fire } = await attach({ sharp: 0 }, (df) => translating(df * speed));++ expect(group.style.display).toBe("");+ expect(word.hasAttribute(HIDING)).toBe(true);++ speed = 0;+ fire();+ await Promise.resolve();++ expect(group.style.display).toBe("none");+ expect(word.hasAttribute(HIDING)).toBe(false);+ });++ it("leaves the element's own visibility to the timeline at sharp 0", async () => {+ // An autoAlpha fade writes visibility itself; hiding through it would keep the element+ // hidden after the fade brings it back.+ let speed = 1;+ const { word, fire } = await attach({ sharp: 0 }, (df) => translating(df * speed));+ word.style.visibility = "inherit";++ speed = 0;+ fire();+ await Promise.resolve();++ expect(word.style.visibility).toBe("inherit");+ });++ it("smears in the element's current visibility, read without its own marker", async () => {+ // A second frame starts with the marker set, so a read that did not lift it would hide+ // the smear along with the element.+ const { group, word, fire } = await attach({ sharp: 0 });+ fire();+ await Promise.resolve();++ expect(word.hasAttribute(HIDING)).toBe(true);+ expect(group.style.visibility).toBe("");+ });++ it("leaves the smear's visibility to an ancestor while the element shares it", async () => {+ // A clip that ends hides its subtree after the last moving frame; an explicit visible on+ // the group would keep the copies on screen past it.+ const { group } = await attach();++ expect(group.style.display).toBe("");+ expect(group.style.visibility).toBe("");+ });++ it("hides the smear with an element the timeline hides", async () => {+ const { group, word, fire } = await attach();+ word.style.visibility = "hidden";+ fire();+ await Promise.resolve();++ expect(group.style.visibility).toBe("hidden");+ });++ it("does not freeze the element's visibility into the copies", async () => {+ // An element attached while an autoAlpha entrance still hides it would otherwise smear+ // as nothing for the rest of the timeline.+ const observer = installResizeObserver();+ const { word, copies } = await attach();+ const mocked = globalThis.getComputedStyle;+ globalThis.getComputedStyle = ((element: Element) => {+ if (element !== word) return mocked(element);+ const values: Record<string, string> = { visibility: "hidden", color: "red" };+ return Object.assign(Object.create(mocked(element)), Object.keys(values), {+ length: 2,+ getPropertyValue: (name: string) => values[name] ?? "",+ });+ }) as typeof globalThis.getComputedStyle;++ observer.resize();++ expect(copies[0]?.style.color).toBe("red");+ expect(copies[0]?.style.visibility).toBe("");});it("carries the element's own opacity on the smear", async () => {@@ -501,6 +594,61 @@ describe("motion-blur declarative attribute", () => {expect(target.groups()[0]?.children).toHaveLength(5);});+ it("keeps a descendant's own hiding in a copy of a target hidden at attach", async () => {+ // An autoAlpha entrance hides the target when it is blurred. A child hidden by its own+ // rule must still differ from it, or the smear would show what the element hides.+ const target = declare("");+ const own = document.createElement("span");+ const inheriting = document.createElement("span");+ target.word.append(own, inheriting);+ target.word.style.setProperty("visibility", "hidden", "important");+ const mocked = globalThis.getComputedStyle;+ const resolved = (element: Element, value: string) =>+ Object.assign(Object.create(mocked(element)), ["visibility"], {+ length: 1,+ visibility: value,+ getPropertyValue: (name: string) => (name === "visibility" ? value : ""),+ });+ globalThis.getComputedStyle = ((element: Element) => {+ if (element === own) return resolved(element, "hidden");+ if (element === inheriting || element === target.word) {+ return resolved(element, wordVisibility(target.word));+ }+ return mocked(element);+ }) as typeof globalThis.getComputedStyle;++ target.register();+ target.fire();+ await Promise.resolve();++ const copy = target.groups()[0]?.children[0];+ if (!copy) throw new Error("motion-blur group carries no copies");+ expect((copy.children[0] as HTMLElement).style.visibility).toBe("hidden");+ expect((copy.children[1] as HTMLElement).style.visibility).toBe("");+ expect(target.word.style.visibility).toBe("hidden");+ expect(target.word.style.getPropertyPriority("visibility")).toBe("important");+ });++ it("puts a hidden target's visibility back when copying its styles throws", async () => {+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});+ const target = declare("");+ const child = document.createElement("span");+ target.word.append(child);+ target.word.style.visibility = "hidden";+ const mocked = globalThis.getComputedStyle;+ globalThis.getComputedStyle = ((element: Element) => {+ if (element === child) throw new Error("no style");+ return mocked(element);+ }) as typeof globalThis.getComputedStyle;++ target.register();++ expect(target.groups()).toHaveLength(0);+ expect(target.word.style.visibility).toBe("hidden");+ expect(target.word.style.getPropertyPriority("visibility")).toBe("");+ warn.mockRestore();+ });+it("leaves a target alone when another composition registers", async () => {// One page can hold several compositions, and a target belongs to the nearest one.const target = declare("");@@ -764,6 +912,18 @@ describe("motion-blur declarative attribute, the cases only executing found", ()expect(leading).toBeCloseTo(reference.leadingDisplacementPx, 1);});+ it("refuses a sharp other than 0 or 1 instead of reading it as crisp", async () => {+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});+ const target = declare('{"sharp": 0.5}');++ target.register();+ await target.settle();++ expect(target.groups()).toHaveLength(0);+ expect(String(warn.mock.calls[0]?.[0])).toContain("needs 0 or 1 for sharp");+ warn.mockRestore();+ });+it("refuses an option name it does not know instead of rendering with the defaults", async () => {// The likeliest typo in a JSON object is the key, and reading it as defaults is exactly// the silent no-op the attribute exists to remove.diff --git a/registry/blocks/gooey-split/gooey-split.html b/registry/blocks/gooey-split/gooey-split.htmlnew file mode 100644index 0000000000..b4037d1081--- /dev/null+++ b/registry/blocks/gooey-split/gooey-split.html@@ -0,0 +1,957 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="utf-8" />+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/gsap.min.js"></script>+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/CustomEase.min.js"></script>+ <!--+ gooey-split: a dot splits into a three-dot menu with a gooey neck, spins into a+ swirl mark under directional motion blur, breaks back into three dots, and merges.++ Goo is an SVG filter (blur, then an alpha threshold) on the box holding the dots,+ on only while they split and merge. Motion blur is the motion-blur component's+ shutter snippet, verbatim: every moving part moves by transform alone, set from a+ pure function of time through GSAP modifiers, so the shutter's sub-frame seeks+ sample the real trajectory.+ -->+ <style>+ *,+ *::before,+ *::after {+ margin: 0;+ padding: 0;+ box-sizing: border-box;+ }+ body {+ background: #f9da41;+ overflow: hidden;+ }+ #root-gooey-split {+ position: relative;+ width: 1920px;+ height: 1080px;+ overflow: hidden;+ background: #f9da41;+ }+ .gs-stage {+ position: absolute;+ inset: 0;+ }+ .gs-tile {+ position: absolute;+ left: 581px;+ top: 161px;+ width: 758px;+ height: 758px;+ border-radius: 80px;+ background: rgba(28, 24, 15, 0.07);+ opacity: 0;+ }+ /* Tight around the dots at full spread: the goo filter costs per pixel of this box. */+ .gs-goo {+ position: absolute;+ left: 810px;+ top: 220px;+ width: 300px;+ height: 640px;+ filter: url(#gs-goo);+ }+ .gs-dot {+ position: absolute;+ left: 96px;+ top: 266px;+ width: 108px;+ height: 108px;+ border-radius: 50%;+ background: #1c180f;+ }+ .gs-blade {+ position: absolute;+ left: 662px;+ top: 242px;+ width: 596px;+ height: 596px;+ }+ .gs-blade svg {+ display: block;+ fill: #1c180f;+ stroke: #1c180f;+ stroke-width: 20px;+ stroke-linejoin: round;+ }+ .gs-centre {+ position: absolute;+ left: 890px;+ top: 470px;+ width: 140px;+ height: 140px;+ border-radius: 50%;+ background: #1c180f;+ }+ </style>+ </head>+ <body>+ <div+ id="root-gooey-split"+ data-composition-id="gooey-split"+ data-start="0"+ data-duration="4.7"+ data-fps="60"+ data-width="1920"+ data-height="1080"+ >+ <svg width="0" height="0" style="position: absolute" aria-hidden="true">+ <filter id="gs-goo" color-interpolation-filters="sRGB">+ <feGaussianBlur stdDeviation="28" />+ <!-- Ink wherever the blurred alpha clears 0.392, the alpha at a lone dot's own edge. -->+ <feColorMatrix values="0 0 0 0 0.110 0 0 0 0 0.094 0 0 0 0 0.059 0 0 0 24 -8.9" />+ </filter>+ </svg>+ <div class="gs-stage" id="gs-stage">+ <div class="gs-tile" id="gs-tile"></div>+ <div class="gs-goo" id="gs-goo-box">+ <div class="gs-dot" id="gs-dot-0"></div>+ <div class="gs-dot" id="gs-dot-1"></div>+ <div class="gs-dot" id="gs-dot-2"></div>+ </div>+ <div class="gs-blade" id="gs-blade-0">+ <svg viewBox="-298 -298 596 596" width="596" height="596"><path /></svg>+ </div>+ <div class="gs-blade" id="gs-blade-1">+ <svg viewBox="-298 -298 596 596" width="596" height="596"><path /></svg>+ </div>+ <div class="gs-blade" id="gs-blade-2">+ <svg viewBox="-298 -298 596 596" width="596" height="596"><path /></svg>+ </div>+ <div class="gs-centre" id="gs-centre"></div>+ </div>+ <div+ id="gs-clip"+ class="clip"+ data-start="0"+ data-duration="4.7"+ data-track-index="0"+ style="position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none"+ ></div>+ </div>+ <script>+ (function () {+ /* SHUTTER_SNIPPET_START */+ if (!window._hfMbUid) window._hfMbUid = 0;+ if (!window._hfMbAttached) window._hfMbAttached = new WeakSet();+ if (!window._hfMbSkipped) window._hfMbSkipped = new WeakSet();+ if (!window._hfMbProxies) window._hfMbProxies = new WeakSet();+ if (!window._hfMbTimeline) window._hfMbTimeline = new WeakMap();+ if (!window._hfMbWarned) window._hfMbWarned = new WeakSet();++ // The declarative form. A copy of a target must not carry it, or the copy is swept+ // as a target of its own; the group's own marker is `data-hf-motion-blur-group`.+ var SWEEP_ATTR = "data-hf-motion-blur";+ // About eight seconds. Long enough for an asynchronously mounted sub-composition, short+ // enough that a page with a genuine mistake in it reports before anyone stops watching.+ var POLL_MS = 32;+ var POLL_TICKS = 250;+ var SWEEP_SELECTOR = "[" + SWEEP_ATTR + "]";+ var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps", "sharp"];++ // A copy is a deep clone, so the attribute rides along on the root AND on every marked+ // descendant. Any one left behind is swept as a target of its own, which clones again.+ var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];++ // sharp 0 hides a moving target through this marker rather than its own visibility,+ // which the author's timeline (autoAlpha) may be writing too.+ var HIDE_ATTR = "data-hf-motion-blur-hiding";++ function installHideRule() {+ if (document.getElementById("hf-mb-hide")) return;+ var rule = document.createElement("style");+ rule.id = "hf-mb-hide";+ rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";+ (document.head || document.documentElement).appendChild(rule);+ }++ function stripAttrs(el) {+ for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);+ }++ function stripCopyAttrs(root) {+ stripAttrs(root);+ var inner = root.querySelectorAll("[" + COPY_STRIP.join("],[") + "]");+ for (var i = 0; i < inner.length; i++) stripAttrs(inner[i]);+ }++ // Shutter length is measured in frames, so the snippet must know the composition+ // frame rate: explicit option, else the target's OWN root, else the first root in+ // the document, else 30. The target's root is what makes two compositions on one+ // page read their own data-fps instead of sharing the first one written.+ function resolveFps(optionFps, target) {+ var explicit = Number(optionFps);+ if (explicit > 0) return explicit;++ var scoped = target ? target.closest("[data-composition-id][data-fps]") : null;+ var root = scoped || 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;+ }++ // A resolved `transform` is either "none", a 2D matrix(a,b,c,d,e,f) or a 3D+ // matrix3d of 16. Splitting the numbers into the linear part and the+ // translation is what lets the deadband below use a pixel tolerance on the+ // one and an angle/ratio tolerance on the other.+ function parseTransform(value) {+ if (!value || value === "none") return { linear: [1, 0, 0, 1], translate: [0, 0, 0] };+ var nums = value+ .slice(value.indexOf("(") + 1, -1)+ .split(",")+ .map(parseFloat);+ if (nums.length === 16) {+ return {+ linear: [+ nums[0],+ nums[1],+ nums[2],+ nums[4],+ nums[5],+ nums[6],+ nums[8],+ nums[9],+ nums[10],+ nums[3],+ nums[7],+ nums[11],+ nums[15],+ ],+ translate: [nums[12], nums[13], nums[14]],+ };+ }+ return {+ linear: [nums[0], nums[1], nums[2], nums[3]],+ translate: [nums[4], nums[5], 0],+ };+ }++ // Deadband: half a pixel of travel, a thousandth of a unit of linear change,+ // about 0.06 degrees or 0.1% of scale. Below it the average is the source.+ // The 2D and 3D forms have different arities, so a change of form counts as+ // movement rather than being compared component by component.+ function differs(a, b) {+ if (a.linear.length !== b.linear.length) return true;+ for (var i = 0; i < a.linear.length; i++) {+ if (Math.abs(a.linear[i] - b.linear[i]) > 0.001) return true;+ }+ for (var j = 0; j < 3; j++) {+ if (Math.abs(a.translate[j] - b.translate[j]) > 0.5) return true;+ }+ return false;+ }++ window.attachMotionBlur = function (selector, tl, opts) {+ opts = opts || {};+ var shutterAngle = numOption(opts.shutterAngle, 720);+ var shutterPhase = numOption(opts.shutterPhase, -360);+ var requestedSamples = numOption(opts.samplesPerFrame, 16);+ var sharp = opts.sharp !== 0;+ if (!sharp) installHideRule();+ var samples = Number.isFinite(requestedSamples)+ ? Math.max(2, Math.min(64, Math.round(requestedSamples)))+ : 16;+ var items = Array.isArray(selector) ? selector : [selector];+ var targets = items.reduce(function (acc, s) {+ if (typeof s === "string") {+ document.querySelectorAll(s).forEach(function (el) {+ acc.push(el);+ });+ } else if (s instanceof Element) {+ acc.push(s);+ }+ return acc;+ }, []);++ // `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 alpha = String(1 / samples);++ // A copy is styled by nothing that selected the original: dropping the id also+ // drops every `#id` rule that gave it size, colour and font. So each copy carries+ // its own resolved style inline. Chrome returns "" for a computed style's cssText,+ // so the declarations are enumerated rather than taken wholesale.+ // Visibility is not frozen into a copy: its root takes the element's current one from+ // the group each frame, and a descendant keeps its own only where it differs from its+ // parent's. A target hidden at attach (autoAlpha) would otherwise never smear.+ function resolvedStyles(source, out, parentVisibility) {+ var cs = getComputedStyle(source);+ var text = "";+ for (var i = 0; i < cs.length; i++) {+ var value = cs.getPropertyValue(cs[i]);+ var inherited = parentVisibility === undefined || value === parentVisibility;+ if (cs[i] === "visibility" && inherited) continue;+ text += cs[i] + ":" + value + ";";+ }+ // A copy is a still of one instant. Left live, an inherited transition or+ // keyframe animation would carry it somewhere the timeline never sampled.+ out.push(text + "transition:none;animation:none;");+ for (var c = 0; c < source.children.length; c++) {+ resolvedStyles(source.children[c], out, cs.getPropertyValue("visibility"));+ }+ return out;+ }++ function paintResolvedStyles(copy, styles, cursor) {+ copy.style.cssText = styles[cursor.i++];+ for (var c = 0; c < copy.children.length; c++) {+ paintResolvedStyles(copy.children[c], styles, cursor);+ }+ }++ // Perspective applies to a parent's children only, and a copy is a grandchild.+ // Sharing the parent's 3D context would need preserve-3d on the group, which+ // mix-blend-mode flattens, so each copy carries the perspective itself. See the+ // header for what that does to the vanishing point.+ function parentPerspective(el) {+ var value = el.parentNode ? getComputedStyle(el.parentNode).perspective : "none";+ return value && value !== "none" ? "perspective(" + value + ") " : "";+ }++ function attachOne(el) {+ var group = document.createElement("div");+ group.setAttribute("data-hf-motion-blur-group", "hf-mb-" + window._hfMbUid++);+ group.style.cssText =+ "position:absolute;left:0;top:0;width:0;height:0;isolation:isolate;pointer-events:none;display:none;";++ var clones = [];+ for (var k = 0; k < copies; k++) {+ var clone = el.cloneNode(true);+ clone.removeAttribute("id");+ stripCopyAttrs(clone);+ clones.push(clone);+ group.appendChild(clone);+ }+ var s = {+ el: el,+ group: group,+ clones: clones,+ samples: [],+ perspective: "",+ watch: null,+ };++ // Resolved styles and the parent's perspective are px once read, so a+ // container-relative element needs them again when its box changes. Per frame+ // that would walk the whole subtree once per copy; on resize it costs nothing+ // on a fixed-size render and keeps a live preview honest.+ function snapshot() {+ // Read a target hidden right now (an autoAlpha entrance) as shown, so a descendant+ // hidden by its own rule still differs from it; the inline value goes back exactly.+ var hidden = getComputedStyle(el).visibility !== "visible";+ var inline = el.style.getPropertyValue("visibility");+ var priority = el.style.getPropertyPriority("visibility");+ if (hidden) el.style.setProperty("visibility", "visible", "important");+ var styles;+ try {+ styles = resolvedStyles(el, []);+ } finally {+ if (hidden) el.style.setProperty("visibility", inline, priority);+ }+ s.perspective = parentPerspective(el);+ for (var c = 0; c < clones.length; c++) {+ paintResolvedStyles(clones[c], styles, { i: 0 });+ clones[c].style.position = "absolute";+ clones[c].style.margin = "0";+ clones[c].style.opacity = alpha;+ clones[c].style.mixBlendMode = "plus-lighter";+ }+ }++ // Snapshot BEFORE the group enters the page, so a throw in the style walk leaves+ // nothing behind: the record the rollback needs does not exist until it returns.+ snapshot();+ el.parentNode.insertBefore(group, el);+ if (typeof ResizeObserver === "function") {+ s.watch = new ResizeObserver(snapshot);+ s.watch.observe(el);+ }+ return s;+ }++ var state = [];+ // Every element this call marked. A throw inside `attachOne` never returns its+ // record, so `state` alone cannot give the marks back.+ var claimed = [];+ try {+ for (var q = 0; q < targets.length; q++) {+ var candidate = targets[q];+ // One group per element, whether a second call names it or one call names it+ // twice: a second set of copies over the first would double the ink. Marked+ // BEFORE the copies go in: inserting them runs custom-element reactions+ // synchronously, and one that registers a timeline re-enters the write trap.+ if (window._hfMbAttached.has(candidate)) continue;+ window._hfMbAttached.add(candidate);+ window._hfMbTimeline.set(candidate, tl);+ claimed.push(candidate);+ state.push(attachOne(candidate));+ }+ } catch (e) {+ unmark(claimed);+ discard(state);+ throw e;+ }+ // Nothing to blur means nothing to seek: a tracker here would run the whole sample+ // loop every frame over an empty set.+ if (state.length === 0) return;++ // One seek loop drives the whole call, so the window is ONE length, and it belongs+ // to the composition of an element this call actually attached.+ var fps = resolveFps(opts.fps, state[0].el);+ for (var d = 1; d < state.length; d++) {+ if (resolveFps(opts.fps, state[d].el) === fps) continue;+ var line = "one call cannot blur compositions at different frame rates; using ";+ console.warn("[motion-blur] " + line + fps, state[d].el);+ break;+ }++ function readTransform(el) {+ var cs = getComputedStyle(el);+ return {+ css: cs.transform,+ origin: cs.transformOrigin,+ opacity: cs.opacity,+ visibility: cs.visibility,+ parsed: parseTransform(cs.transform),+ };+ }++ var scheduled = false;++ function applyShutter() {+ var shutterTime = shutterAngle / 360 / fps;+ if (!(shutterTime > 0)) {+ state.forEach(function (s) {+ s.group.style.display = "none";+ });+ 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 the resolved transform, 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) {+ s.samples[k] = readTransform(s.el);+ });+ }+ } finally {+ tl.time(t0, true);+ }++ state.forEach(function (s) {+ // Read the element as the timeline left it: the marker is this snippet's own.+ if (!sharp) s.el.removeAttribute(HIDE_ATTR);+ var current = readTransform(s.el);+ var moved = false;+ for (var i = 0; i < copies; i++) {+ if (differs(s.samples[i].parsed, current.parsed)) {+ moved = true;+ break;+ }+ }+ if (!moved) {+ s.group.style.display = "none";+ return;+ }++ // The copies are absolutely positioned inside the group, and the group sits at+ // the origin of the element's own containing block, so the element's offset box+ // places them. Re-read every frame: a beat is free to move the box itself.+ var left = s.el.offsetLeft + "px";+ var top = s.el.offsetTop + "px";+ var width = s.el.offsetWidth + "px";+ var height = s.el.offsetHeight + "px";+ for (var j = 0; j < copies; j++) {+ var clone = s.clones[j];+ clone.style.left = left;+ clone.style.top = top;+ clone.style.width = width;+ clone.style.height = height;+ clone.style.transformOrigin = s.samples[j].origin;+ clone.style.transform =+ s.perspective + (s.samples[j].css === "none" ? "" : s.samples[j].css);+ }+ // The copies are the element's own ink, so they carry its opacity and visibility:+ // a beat that moves and fades at once would otherwise leave a full-strength+ // smear behind a vanishing element. It rides the group, not the copies, whose+ // own opacity is the 1/N shutter weight.+ s.group.style.opacity = current.opacity;+ // Set only where the element differs from its parent: an explicit value would+ // outlive an ancestor that hides later, like a clip that has ended.+ var shared = getComputedStyle(s.el.parentNode).visibility;+ s.group.style.visibility = current.visibility === shared ? "" : current.visibility;+ s.group.style.display = "";+ if (!sharp) s.el.setAttribute(HIDE_ATTR, "");+ });+ }++ // 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 };+ try {+ tl.to(+ _proxy,+ {+ t: 1,+ duration: Math.max(tl.duration(), 0.1),+ ease: "none",+ onUpdate: function () {+ if (scheduled) return;+ scheduled = true;+ Promise.resolve().then(function () {+ scheduled = false;+ applyShutter();+ });+ },+ },+ 0,+ );+ } catch (e) {+ unmark(claimed);+ discard(state);+ throw e;+ }+ };++ // An empty attribute means defaults; anything else is a JSON options object. A value that+ // is not an options object is skipped loudly rather than read as defaults, because a typo+ // in it would otherwise render as a silently unblurred element.+ function sweepOptions(el) {+ var text = (el.getAttribute(SWEEP_ATTR) || "").trim();+ if (text === "") return {};+ var parsed = null;+ try {+ parsed = JSON.parse(text);+ } catch (e) {+ return refuse(el, "is not JSON: " + text);+ }+ // `null`, a number and a string all parse. None of them is a set of options.+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {+ return refuse(el, "is not a JSON object: " + text);+ }+ var bad = unknownKey(parsed);+ if (bad !== null) return refuse(el, "names no such option: " + bad);+ var wrong = nonNumber(parsed);+ if (wrong !== null) return refuse(el, "needs a number for " + wrong);+ if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {+ return refuse(el, "needs 0 or 1 for sharp");+ }+ return parsed;+ }++ // A misspelled key is the likeliest typo in a JSON object, and reading it as+ // defaults is the silent no-op this attribute exists to remove.+ function unknownKey(parsed) {+ for (var key in parsed) {+ if (OPTION_KEYS.indexOf(key) < 0) return key;+ }+ return null;+ }++ // A key with a value the shutter cannot use is the same silent no-op as a key it does+ // not know: a non-numeric angle hides the smear, a non-numeric phase parks every copy+ // at the timeline's start. JSON gives real numbers, so anything else is a typo.+ function nonNumber(parsed) {+ for (var i = 0; i < OPTION_KEYS.length; i++) {+ var held = parsed[OPTION_KEYS[i]];+ if (held === undefined) continue;+ if (typeof held !== "number" || !Number.isFinite(held)) return OPTION_KEYS[i];+ }+ return null;+ }++ // A throw partway through an attach leaves an element blurred by nothing, so the copies+ // go too, along with the observer that would otherwise keep walking a detached subtree+ // on every resize of an element nothing blurs.+ // The mark is what a second trigger reads, so it is the first thing to give back.+ function unmark(els) {+ for (var i = 0; i < els.length; i++) {+ window._hfMbAttached.delete(els[i]);+ window._hfMbTimeline.delete(els[i]);+ }+ }++ function discard(state) {+ for (var i = 0; i < state.length; i++) {+ var s = state[i];+ if (s.watch !== null) s.watch.disconnect();+ if (s.group.parentNode !== null) s.group.parentNode.removeChild(s.group);+ }+ }++ function refuse(el, why) {+ window._hfMbSkipped.add(el);+ console.warn("[motion-blur] " + SWEEP_ATTR + " " + why, el);+ return null;+ }++ // An element belongs to the nearest composition above it, so a sub-composition's+ // targets follow that sub-composition's own timeline.+ function compositionOf(el) {+ var host = el.closest("[data-composition-id]");+ return host ? host.getAttribute("data-composition-id") : null;+ }++ // Anything else registered on the container is somebody else's bookkeeping: a+ // timeline is the thing this snippet can seek and extend.+ function isTimeline(value) {+ return !!value && typeof value.time === "function" && typeof value.to === "function";+ }++ // Attached, or skipped as unparseable. Both are terminal, so a later trigger must not+ // report or attach the element twice.+ function handled(el) {+ return window._hfMbAttached.has(el) || window._hfMbSkipped.has(el);+ }++ // The timeline registered for an element's own composition, or null. Read from the+ // registry rather than taken from whoever wrote it, so every trigger agrees.+ function timelineFor(el) {+ var id = compositionOf(el);+ if (id === null) return null;+ var registry = window.__timelines;+ var found = registry ? registry[id] : null;+ return isTimeline(found) ? found : null;+ }++ // A marked element whose parent is not an Element has no target above it: the parent+ // of a root is the Document, which has no `closest`.+ function nestedInTarget(el) {+ var parent = el.parentNode;+ if (parent === null || typeof parent.closest !== "function") return false;+ return parent.closest(SWEEP_SELECTOR) !== null;+ }++ // One owner of attaching one element. Answers whether the element still needs a trigger.+ function claim(el) {+ var tl = timelineFor(el);+ if (handled(el)) {+ var owner = window._hfMbTimeline.get(el);+ // Re-registering a key with a DIFFERENT timeline leaves the copies driven by the one+ // nobody seeks, which renders sharp and says nothing. Report it rather than guess.+ var changed = tl !== null && owner !== undefined && owner !== tl;+ if (changed && !window._hfMbWarned.has(el)) {+ window._hfMbWarned.add(el);+ console.warn(+ "[motion-blur] a second timeline registered for this element; the copies still follow the first",+ el,+ );+ }+ return true;+ }+ // Its group would be inserted into the live outer element, so the outer target's+ // style replay would walk a subtree its cursor no longer matches.+ if (nestedInTarget(el)) {+ refuse(el, "cannot blur a target inside another target; blur one of them");+ return true;+ }+ var opts = sweepOptions(el);+ if (opts === null) return true;+ if (tl === null) return false;+ window.attachMotionBlur(el, tl, opts);+ return true;+ }++ // Returns the elements still waiting for their composition to register a timeline.+ // The trap below runs this INSIDE the author's registration statement, so one bad+ // target must not abort the rest of their composition script.+ function sweep() {+ var pending = [];+ document.querySelectorAll(SWEEP_SELECTOR).forEach(function (el) {+ try {+ if (!claim(el)) pending.push(el);+ } catch (e) {+ window._hfMbSkipped.add(el);+ console.warn("[motion-blur] could not blur this element: " + e, el);+ }+ });+ return pending;+ }++ // Registering a timeline is the moment the author has finished building it, so trapping+ // the write attaches before the renderer captures a frame. A microtask would be too+ // early: it runs before the next `<script>` tag.+ function registrationProxy(container) {+ var proxy = new Proxy(container, {+ set: function (target, key, value) {+ target[key] = value;+ if (typeof key === "string") sweep();+ return true;+ },+ });+ window._hfMbProxies.add(proxy);+ return proxy;+ }++ function hookRegistration() {+ var held = window.__timelines;+ Object.defineProperty(window, "__timelines", {+ configurable: true,+ enumerable: true,+ get: function () {+ return held;+ },+ set: function (value) {+ var container = !!value && typeof value === "object";+ var fresh = container && !window._hfMbProxies.has(value);+ held = fresh ? registrationProxy(value) : value;+ if (fresh) sweep();+ },+ });+ // A container assigned before this snippet ran is replayed through the setter, so a+ // timeline already registered on it is swept too.+ if (held !== undefined) window.__timelines = held;+ }++ // The trap above cannot see every registration: the runtime owns the registry object,+ // wraps it per sub-composition, and mounts nested compositions asynchronously. So the+ // registry is also POLLED, which needs no cooperation from whoever writes it.+ function poll(ticks) {+ var pending = sweep();+ // The WHOLE budget, every time. Stopping the first tick nothing is pending kills the+ // poll one tick into an ordinary page, which is before a late composition arrives.+ if (ticks > 0) {+ setTimeout(function () {+ poll(ticks - 1);+ }, POLL_MS);+ return;+ }+ if (pending.length === 0) return;+ var count = pending.length + " element(s) carry " + SWEEP_ATTR;+ console.warn(+ "[motion-blur] " + count + ", and no composition registered a timeline for them",+ pending,+ );+ }++ if (!window._hfMbHooked) {+ window._hfMbHooked = true;+ hookRegistration();+ poll(POLL_TICKS);+ }+ /* SHUTTER_SNIPPET_END */+ })();+ </script>+ <script>+ (function () {+ "use strict";+ var DUR = 4.7;+ var SPREAD = 190; // dot spacing in the menu+ var ORBIT = 197; // where each dot rests inside its blade+ var R_OUT = 298;+ var R_IN = 118;+ var GAP = 44;+ var ROUND = 10; // blade corner radius: the path is inset by it and stroked back out+ var TWIST = -18; // degrees the blade gaps curl from the inner to the outer edge+ var SHUTTER = 360; // degrees, centred on the frame++ // Top, middle and bottom dot. Each spins clockwise from `from`, `spinIn` degrees+ // into the mark and `spinOut` more back to the menu; they rest 120 degrees apart.+ var PIECES = [+ { from: -90, menuR: SPREAD, spinIn: 360, spinOut: 360 },+ { from: 180, menuR: 0, spinIn: 330, spinOut: 390 },+ { from: 90, menuR: SPREAD, spinIn: 300, spinOut: 420 },+ ];+ // Beat windows in seconds, read off the reference frame by frame.+ var SPLITS = [+ [0.33, 0.73],+ [3.43, 3.83],+ ];+ var MERGES = [+ [2.69, 3.03],+ [4.2, 4.54],+ ];+ var SPIN_IN = [1.03, 1.6];+ var SPIN_OUT = [2.075, 2.67];+ var BLADE_GROW = [1.24, 1.52];+ var BLADE_SHRINK = [2.1, 2.4];+ var CENTRE_GROW = [1.3, 1.5];+ var CENTRE_SHRINK = [2.115, 2.28];+ // Each dot swells along its path while its blade grows out of it, and on the way back.+ var SWELLS = [+ [1.12, 1.29, 1.47],+ [2.1, 2.24, 2.45],+ ];+ var SWELL_ALONG = 0.7;+ var SWELL_ACROSS = 0.15;++ var swift = CustomEase.create("gs-swift", "M0,0 C0.25,0 0.2,1 1,1");+ var settle = CustomEase.create("gs-settle", "M0,0 C0.43,0 0.39,1 1,1");+ var split = CustomEase.create("gs-split", "M0,0 C0.4,0 0.2,1 1,1");+ var inOut = gsap.parseEase("power2.inOut");+ var easeOut = gsap.parseEase("power1.out");+ var circOut = gsap.parseEase("circ.out");+ var bladeOut = gsap.parseEase("power3.out");+ var linear = gsap.parseEase("none");++ function span(t, w, ease) {+ return ease(gsap.utils.clamp(0, 1, (t - w[0]) / (w[1] - w[0])));+ }++ function spread(t) {+ if (t < MERGES[0][0]) return span(t, SPLITS[0], split);+ if (t < SPLITS[1][0]) return 1 - span(t, MERGES[0], settle);+ if (t < MERGES[1][0]) return span(t, SPLITS[1], split);+ return 1 - span(t, MERGES[1], settle);+ }++ function swell(t) {+ var s = 0;+ SWELLS.forEach(function (w) {+ s += span(t, [w[0], w[1]], inOut) - span(t, [w[1], w[2]], inOut);+ });+ return s;+ }++ function rad(deg) {+ return (deg * Math.PI) / 180;+ }++ function piece(p, t) {+ var spinIn = span(t, SPIN_IN, swift);+ var spinOut = span(t, SPIN_OUT, swift);+ var angle = p.from + p.spinIn * spinIn + p.spinOut * spinOut;+ var radius = p.menuR * spread(t) + (ORBIT - p.menuR) * (spinIn - spinOut);+ var swollen = swell(t);+ return {+ x: radius * Math.cos(rad(angle)),+ y: radius * Math.sin(rad(angle)),+ turn: angle - (p.from + p.spinIn),+ rotation: angle,+ scaleX: 1 + SWELL_ACROSS * swollen,+ scaleY: 1 + SWELL_ALONG * swollen,+ };+ }++ // A blade rides its dot: anchored at the dot's rest point, turned and scaled about+ // it, and carried to wherever the dot is. Scale 0 hides it inside the dot.+ function blade(p, rest, t) {+ var at = piece(p, t);+ var grown = span(t, BLADE_GROW, bladeOut) - span(t, BLADE_SHRINK, linear);+ return {+ x: at.x - rest.x,+ y: at.y - rest.y,+ rotation: at.turn,+ scaleX: grown,+ scaleY: grown,+ };+ }++ function edge(mid, side, r) {+ var swirl = (TWIST * (r - ORBIT)) / (R_OUT - R_IN);+ var theta = rad(mid + side * 60 + swirl) - (side * (GAP / 2 + ROUND)) / r;+ return (r * Math.cos(theta)).toFixed(2) + "," + (r * Math.sin(theta)).toFixed(2);+ }++ function bladePath(mid) {+ var lo = [];+ var hi = [];+ for (var k = 0; k <= 16; k++) {+ var r = R_IN + ROUND + ((R_OUT - R_IN - 2 * ROUND) * k) / 16;+ lo.push(edge(mid, -1, r));+ hi.unshift(edge(mid, 1, r));+ }+ return [+ "M" + lo.join(" L"),+ "A" + (R_OUT - ROUND) + "," + (R_OUT - ROUND) + " 0 0 1 " + hi[0],+ "L" + hi.join(" L"),+ "A" + (R_IN + ROUND) + "," + (R_IN + ROUND) + " 0 0 0 " + lo[0],+ "Z",+ ].join(" ");+ }++ var tl = gsap.timeline({ paused: true });++ // Tweens a time value 0 to DUR on `el` and lets `read(t)` decide each property.+ function drive(el, props, read) {+ var from = {};+ var to = { duration: DUR, ease: "none", modifiers: {} };+ props.forEach(function (prop) {+ from[prop] = 0;+ to[prop] = DUR;+ to.modifiers[prop] = gsap.utils.unitize(function (t) {+ return read(t)[prop];+ });+ });+ tl.fromTo(el, from, to, 0);+ }++ var MOVES = ["x", "y", "rotation", "scaleX", "scaleY"];+ PIECES.forEach(function (p, i) {+ drive(document.getElementById("gs-dot-" + i), MOVES, function (t) {+ return piece(p, t);+ });+ var el = document.getElementById("gs-blade-" + i);+ var restAngle = p.from + p.spinIn;+ var rest = { x: ORBIT * Math.cos(rad(restAngle)), y: ORBIT * Math.sin(rad(restAngle)) };+ el.querySelector("path").setAttribute("d", bladePath(restAngle));+ el.style.transformOrigin = R_OUT + rest.x + "px " + (R_OUT + rest.y) + "px";+ drive(el, MOVES, function (t) {+ return blade(p, rest, t);+ });+ });++ drive(document.getElementById("gs-centre"), ["scaleX", "scaleY"], function (t) {+ var grown = span(t, CENTRE_GROW, easeOut) - span(t, CENTRE_SHRINK, circOut);+ return { scaleX: grown, scaleY: grown };+ });++ // Spinning dots under the goo filter would threshold their blur away.+ var goo = document.getElementById("gs-goo-box");+ tl.set(goo, { filter: "none" }, 0.95);+ tl.set(goo, { filter: "url(#gs-goo)" }, 2.67);++ var tile = document.getElementById("gs-tile");+ [+ [0.32, 2.08],+ [3.42, 4.2],+ ].forEach(function (shown) {+ tl.fromTo(+ tile,+ { opacity: 0, scale: 0.975 },+ { opacity: 1, scale: 1, duration: 0.15, ease: "power1.inOut", immediateRender: false },+ shown[0],+ );+ tl.to(tile, { opacity: 0, duration: 0.15, ease: "power1.inOut" }, shown[1]);+ });+ // The press on the menu before it spins.+ tl.to(tile, { backgroundColor: "rgba(28, 24, 15, 0.1)", duration: 0.05 }, 0.93);+ tl.to(tile, { backgroundColor: "rgba(28, 24, 15, 0.07)", duration: 0.07 }, 1.03);++ // After every tween: the blur's tracker needs the timeline's final duration. No crisp+ // copy over the smear, and a one-frame shutter: the reference smears each blob end to end.+ attachMotionBlur(".gs-dot, .gs-blade, .gs-centre", tl, {+ shutterAngle: SHUTTER,+ shutterPhase: -SHUTTER / 2,+ sharp: 0,+ });++ window.__timelines = window.__timelines || {};+ window.__timelines["gooey-split"] = tl;+ })();+ </script>+ </body>+</html>diff --git a/registry/blocks/gooey-split/registry-item.json b/registry/blocks/gooey-split/registry-item.jsonnew file mode 100644index 0000000000..65a4fb138e--- /dev/null+++ b/registry/blocks/gooey-split/registry-item.json@@ -0,0 +1,17 @@+{+ "$schema": "https://hyperframes.heygen.com/schema/registry-item.json",+ "name": "gooey-split",+ "type": "hyperframes:block",+ "title": "Gooey Split",+ "description": "A dot splits into a three-dot menu with a gooey metaball neck, spins into a swirl mark under directional shutter motion blur, then breaks back into three dots and merges into one. The goo is an SVG blur-and-threshold filter on the dots; the blur integrates each part along its real trajectory, so the smear follows the direction and speed of the spin.",+ "dimensions": { "width": 1920, "height": 1080 },+ "duration": 4.7,+ "tags": ["effect", "gooey", "metaball", "motion-blur", "morph", "logo", "icon"],+ "files": [+ {+ "path": "gooey-split.html",+ "target": "compositions/gooey-split.html",+ "type": "hyperframes:composition"+ }+ ]+}diff --git a/registry/components/motion-blur/demo.html b/registry/components/motion-blur/demo.htmlindex 8a8eac71b2..025e427ffe 100644--- a/registry/components/motion-blur/demo.html+++ b/registry/components/motion-blur/demo.html@@ -274,12 +274,24 @@var POLL_MS = 32;var POLL_TICKS = 250;var SWEEP_SELECTOR = "[" + SWEEP_ATTR + "]";- var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps"];+ var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps", "sharp"];// A copy is a deep clone, so the attribute rides along on the root AND on every marked// descendant. Any one left behind is swept as a target of its own, which clones again.var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];+ // sharp 0 hides a moving target through this marker rather than its own visibility,+ // which the author's timeline (autoAlpha) may be writing too.+ var HIDE_ATTR = "data-hf-motion-blur-hiding";++ function installHideRule() {+ if (document.getElementById("hf-mb-hide")) return;+ var rule = document.createElement("style");+ rule.id = "hf-mb-hide";+ rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";+ (document.head || document.documentElement).appendChild(rule);+ }+function stripAttrs(el) {for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);}@@ -366,6 +378,8 @@var shutterAngle = numOption(opts.shutterAngle, 720);var shutterPhase = numOption(opts.shutterPhase, -360);var requestedSamples = numOption(opts.samplesPerFrame, 16);+ var sharp = opts.sharp !== 0;+ if (!sharp) installHideRule();var samples = Number.isFinite(requestedSamples)? Math.max(2, Math.min(64, Math.round(requestedSamples))): 16;@@ -392,17 +406,23 @@// drops every `#id` rule that gave it size, colour and font. So each copy carries// its own resolved style inline. Chrome returns "" for a computed style's cssText,// so the declarations are enumerated rather than taken wholesale.- function resolvedStyles(source, out) {+ // Visibility is not frozen into a copy: its root takes the element's current one from+ // the group each frame, and a descendant keeps its own only where it differs from its+ // parent's. A target hidden at attach (autoAlpha) would otherwise never smear.+ function resolvedStyles(source, out, parentVisibility) {var cs = getComputedStyle(source);var text = "";for (var i = 0; i < cs.length; i++) {- text += cs[i] + ":" + cs.getPropertyValue(cs[i]) + ";";+ var value = cs.getPropertyValue(cs[i]);+ var inherited = parentVisibility === undefined || value === parentVisibility;+ if (cs[i] === "visibility" && inherited) continue;+ text += cs[i] + ":" + value + ";";}// A copy is a still of one instant. Left live, an inherited transition or// keyframe animation would carry it somewhere the timeline never sampled.out.push(text + "transition:none;animation:none;");for (var c = 0; c < source.children.length; c++) {- resolvedStyles(source.children[c], out);+ resolvedStyles(source.children[c], out, cs.getPropertyValue("visibility"));}return out;}@@ -451,7 +471,18 @@// that would walk the whole subtree once per copy; on resize it costs nothing// on a fixed-size render and keeps a live preview honest.function snapshot() {- var styles = resolvedStyles(el, []);+ // Read a target hidden right now (an autoAlpha entrance) as shown, so a descendant+ // hidden by its own rule still differs from it; the inline value goes back exactly.+ var hidden = getComputedStyle(el).visibility !== "visible";+ var inline = el.style.getPropertyValue("visibility");+ var priority = el.style.getPropertyPriority("visibility");+ if (hidden) el.style.setProperty("visibility", "visible", "important");+ var styles;+ try {+ styles = resolvedStyles(el, []);+ } finally {+ if (hidden) el.style.setProperty("visibility", inline, priority);+ }s.perspective = parentPerspective(el);for (var c = 0; c < clones.length; c++) {paintResolvedStyles(clones[c], styles, { i: 0 });@@ -515,6 +546,7 @@css: cs.transform,origin: cs.transformOrigin,opacity: cs.opacity,+ visibility: cs.visibility,parsed: parseTransform(cs.transform),};}@@ -550,6 +582,8 @@}state.forEach(function (s) {+ // Read the element as the timeline left it: the marker is this snippet's own.+ if (!sharp) s.el.removeAttribute(HIDE_ATTR);var current = readTransform(s.el);var moved = false;for (var i = 0; i < copies; i++) {@@ -580,12 +614,17 @@clone.style.transform =s.perspective + (s.samples[j].css === "none" ? "" : s.samples[j].css);}- // The copies are the element's own ink, so they have to carry its opacity too:+ // The copies are the element's own ink, so they carry its opacity and visibility:// a beat that moves and fades at once would otherwise leave a full-strength// smear behind a vanishing element. It rides the group, not the copies, whose// own opacity is the 1/N shutter weight.s.group.style.opacity = current.opacity;+ // Set only where the element differs from its parent: an explicit value would+ // outlive an ancestor that hides later, like a clip that has ended.+ var shared = getComputedStyle(s.el.parentNode).visibility;+ s.group.style.visibility = current.visibility === shared ? "" : current.visibility;s.group.style.display = "";+ if (!sharp) s.el.setAttribute(HIDE_ATTR, "");});}@@ -639,6 +678,9 @@if (bad !== null) return refuse(el, "names no such option: " + bad);var wrong = nonNumber(parsed);if (wrong !== null) return refuse(el, "needs a number for " + wrong);+ if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {+ return refuse(el, "needs 0 or 1 for sharp");+ }return parsed;}diff --git a/registry/components/motion-blur/motion-blur.html b/registry/components/motion-blur/motion-blur.htmlindex b07c9118d4..aebd983b8f 100644--- a/registry/components/motion-blur/motion-blur.html+++ b/registry/components/motion-blur/motion-blur.html@@ -33,7 +33,8 @@No single copy ever exceeds 1/N, so a moving edge resolves as astaircase of ghosts behind a solid frame-time instance. The groupcarries the element's own opacity, so a beat that moves and fades at- once fades its smear with it.+ once fades its smear with it. With `sharp: 0` the element is hidden+ while it moves instead, leaving only the shutter average.4. When every sampled transform collapses to the current one (element atrest), the group is hidden so the element renders sharp.@@ -111,8 +112,14 @@target's own composition root, else 30). Pass itexplicitly when rendering with an fps override(`hyperframes render --fps`).-- A key that is none of the four, or a value that is not a finite number, is+ sharp — 1 (default) paints the element itself, crisp, over its+ smear; 0 hides it while it moves, leaving only the+ shutter average: a soft blur with no frame-time edge.+ It hides through a marker attribute, never the+ element's own visibility, so autoAlpha still works+ (an inline visibility !important on it wins).++ A key that is none of the five, or a value that is not a finite number, isrefused by name rather than read as defaults. Both halves matter: anon-numeric angle hides the smear, and a non-numeric phase seeks every copyto NaN, which parks them at the timeline's start.@@ -136,12 +143,24 @@var POLL_MS = 32;var POLL_TICKS = 250;var SWEEP_SELECTOR = "[" + SWEEP_ATTR + "]";- var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps"];+ var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps", "sharp"];// A copy is a deep clone, so the attribute rides along on the root AND on every marked// descendant. Any one left behind is swept as a target of its own, which clones again.var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];+ // sharp 0 hides a moving target through this marker rather than its own visibility,+ // which the author's timeline (autoAlpha) may be writing too.+ var HIDE_ATTR = "data-hf-motion-blur-hiding";++ function installHideRule() {+ if (document.getElementById("hf-mb-hide")) return;+ var rule = document.createElement("style");+ rule.id = "hf-mb-hide";+ rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";+ (document.head || document.documentElement).appendChild(rule);+ }+function stripAttrs(el) {for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);}@@ -228,6 +247,8 @@var shutterAngle = numOption(opts.shutterAngle, 720);var shutterPhase = numOption(opts.shutterPhase, -360);var requestedSamples = numOption(opts.samplesPerFrame, 16);+ var sharp = opts.sharp !== 0;+ if (!sharp) installHideRule();var samples = Number.isFinite(requestedSamples)? Math.max(2, Math.min(64, Math.round(requestedSamples))): 16;@@ -254,17 +275,23 @@// drops every `#id` rule that gave it size, colour and font. So each copy carries// its own resolved style inline. Chrome returns "" for a computed style's cssText,// so the declarations are enumerated rather than taken wholesale.- function resolvedStyles(source, out) {+ // Visibility is not frozen into a copy: its root takes the element's current one from+ // the group each frame, and a descendant keeps its own only where it differs from its+ // parent's. A target hidden at attach (autoAlpha) would otherwise never smear.+ function resolvedStyles(source, out, parentVisibility) {var cs = getComputedStyle(source);var text = "";for (var i = 0; i < cs.length; i++) {- text += cs[i] + ":" + cs.getPropertyValue(cs[i]) + ";";+ var value = cs.getPropertyValue(cs[i]);+ var inherited = parentVisibility === undefined || value === parentVisibility;+ if (cs[i] === "visibility" && inherited) continue;+ text += cs[i] + ":" + value + ";";}// A copy is a still of one instant. Left live, an inherited transition or// keyframe animation would carry it somewhere the timeline never sampled.out.push(text + "transition:none;animation:none;");for (var c = 0; c < source.children.length; c++) {- resolvedStyles(source.children[c], out);+ resolvedStyles(source.children[c], out, cs.getPropertyValue("visibility"));}return out;}@@ -313,7 +340,18 @@// that would walk the whole subtree once per copy; on resize it costs nothing// on a fixed-size render and keeps a live preview honest.function snapshot() {- var styles = resolvedStyles(el, []);+ // Read a target hidden right now (an autoAlpha entrance) as shown, so a descendant+ // hidden by its own rule still differs from it; the inline value goes back exactly.+ var hidden = getComputedStyle(el).visibility !== "visible";+ var inline = el.style.getPropertyValue("visibility");+ var priority = el.style.getPropertyPriority("visibility");+ if (hidden) el.style.setProperty("visibility", "visible", "important");+ var styles;+ try {+ styles = resolvedStyles(el, []);+ } finally {+ if (hidden) el.style.setProperty("visibility", inline, priority);+ }s.perspective = parentPerspective(el);for (var c = 0; c < clones.length; c++) {paintResolvedStyles(clones[c], styles, { i: 0 });@@ -377,6 +415,7 @@css: cs.transform,origin: cs.transformOrigin,opacity: cs.opacity,+ visibility: cs.visibility,parsed: parseTransform(cs.transform),};}@@ -412,6 +451,8 @@}state.forEach(function (s) {+ // Read the element as the timeline left it: the marker is this snippet's own.+ if (!sharp) s.el.removeAttribute(HIDE_ATTR);var current = readTransform(s.el);var moved = false;for (var i = 0; i < copies; i++) {@@ -442,12 +483,17 @@clone.style.transform =s.perspective + (s.samples[j].css === "none" ? "" : s.samples[j].css);}- // The copies are the element's own ink, so they have to carry its opacity too:+ // The copies are the element's own ink, so they carry its opacity and visibility:// a beat that moves and fades at once would otherwise leave a full-strength// smear behind a vanishing element. It rides the group, not the copies, whose// own opacity is the 1/N shutter weight.s.group.style.opacity = current.opacity;+ // Set only where the element differs from its parent: an explicit value would+ // outlive an ancestor that hides later, like a clip that has ended.+ var shared = getComputedStyle(s.el.parentNode).visibility;+ s.group.style.visibility = current.visibility === shared ? "" : current.visibility;s.group.style.display = "";+ if (!sharp) s.el.setAttribute(HIDE_ATTR, "");});}@@ -501,6 +547,9 @@if (bad !== null) return refuse(el, "names no such option: " + bad);var wrong = nonNumber(parsed);if (wrong !== null) return refuse(el, "needs a number for " + wrong);+ if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {+ return refuse(el, "needs 0 or 1 for sharp");+ }return parsed;}diff --git a/registry/components/shutter-slam/demo.html b/registry/components/shutter-slam/demo.htmlindex 49c51c7f5d..9aa2ced4d2 100644--- a/registry/components/shutter-slam/demo.html+++ b/registry/components/shutter-slam/demo.html@@ -104,12 +104,24 @@var POLL_MS = 32;var POLL_TICKS = 250;var SWEEP_SELECTOR = "[" + SWEEP_ATTR + "]";- var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps"];+ var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps", "sharp"];// A copy is a deep clone, so the attribute rides along on the root AND on every marked// descendant. Any one left behind is swept as a target of its own, which clones again.var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];+ // sharp 0 hides a moving target through this marker rather than its own visibility,+ // which the author's timeline (autoAlpha) may be writing too.+ var HIDE_ATTR = "data-hf-motion-blur-hiding";++ function installHideRule() {+ if (document.getElementById("hf-mb-hide")) return;+ var rule = document.createElement("style");+ rule.id = "hf-mb-hide";+ rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";+ (document.head || document.documentElement).appendChild(rule);+ }+function stripAttrs(el) {for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);}@@ -196,6 +208,8 @@var shutterAngle = numOption(opts.shutterAngle, 720);var shutterPhase = numOption(opts.shutterPhase, -360);var requestedSamples = numOption(opts.samplesPerFrame, 16);+ var sharp = opts.sharp !== 0;+ if (!sharp) installHideRule();var samples = Number.isFinite(requestedSamples)? Math.max(2, Math.min(64, Math.round(requestedSamples))): 16;@@ -222,17 +236,23 @@// drops every `#id` rule that gave it size, colour and font. So each copy carries// its own resolved style inline. Chrome returns "" for a computed style's cssText,// so the declarations are enumerated rather than taken wholesale.- function resolvedStyles(source, out) {+ // Visibility is not frozen into a copy: its root takes the element's current one from+ // the group each frame, and a descendant keeps its own only where it differs from its+ // parent's. A target hidden at attach (autoAlpha) would otherwise never smear.+ function resolvedStyles(source, out, parentVisibility) {var cs = getComputedStyle(source);var text = "";for (var i = 0; i < cs.length; i++) {- text += cs[i] + ":" + cs.getPropertyValue(cs[i]) + ";";+ var value = cs.getPropertyValue(cs[i]);+ var inherited = parentVisibility === undefined || value === parentVisibility;+ if (cs[i] === "visibility" && inherited) continue;+ text += cs[i] + ":" + value + ";";}// A copy is a still of one instant. Left live, an inherited transition or// keyframe animation would carry it somewhere the timeline never sampled.out.push(text + "transition:none;animation:none;");for (var c = 0; c < source.children.length; c++) {- resolvedStyles(source.children[c], out);+ resolvedStyles(source.children[c], out, cs.getPropertyValue("visibility"));}return out;}@@ -281,7 +301,18 @@// that would walk the whole subtree once per copy; on resize it costs nothing// on a fixed-size render and keeps a live preview honest.function snapshot() {- var styles = resolvedStyles(el, []);+ // Read a target hidden right now (an autoAlpha entrance) as shown, so a descendant+ // hidden by its own rule still differs from it; the inline value goes back exactly.+ var hidden = getComputedStyle(el).visibility !== "visible";+ var inline = el.style.getPropertyValue("visibility");+ var priority = el.style.getPropertyPriority("visibility");+ if (hidden) el.style.setProperty("visibility", "visible", "important");+ var styles;+ try {+ styles = resolvedStyles(el, []);+ } finally {+ if (hidden) el.style.setProperty("visibility", inline, priority);+ }s.perspective = parentPerspective(el);for (var c = 0; c < clones.length; c++) {paintResolvedStyles(clones[c], styles, { i: 0 });@@ -345,6 +376,7 @@css: cs.transform,origin: cs.transformOrigin,opacity: cs.opacity,+ visibility: cs.visibility,parsed: parseTransform(cs.transform),};}@@ -380,6 +412,8 @@}state.forEach(function (s) {+ // Read the element as the timeline left it: the marker is this snippet's own.+ if (!sharp) s.el.removeAttribute(HIDE_ATTR);var current = readTransform(s.el);var moved = false;for (var i = 0; i < copies; i++) {@@ -410,12 +444,18 @@clone.style.transform =s.perspective + (s.samples[j].css === "none" ? "" : s.samples[j].css);}- // The copies are the element's own ink, so they have to carry its opacity too:+ // The copies are the element's own ink, so they carry its opacity and visibility:// a beat that moves and fades at once would otherwise leave a full-strength// smear behind a vanishing element. It rides the group, not the copies, whose// own opacity is the 1/N shutter weight.s.group.style.opacity = current.opacity;+ // Set only where the element differs from its parent: an explicit value would+ // outlive an ancestor that hides later, like a clip that has ended.+ var shared = getComputedStyle(s.el.parentNode).visibility;+ s.group.style.visibility =+ current.visibility === shared ? "" : current.visibility;s.group.style.display = "";+ if (!sharp) s.el.setAttribute(HIDE_ATTR, "");});}@@ -469,6 +509,9 @@if (bad !== null) return refuse(el, "names no such option: " + bad);var wrong = nonNumber(parsed);if (wrong !== null) return refuse(el, "needs a number for " + wrong);+ if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {+ return refuse(el, "needs 0 or 1 for sharp");+ }return parsed;}diff --git a/registry/components/shutter-slam/shutter-slam.html b/registry/components/shutter-slam/shutter-slam.htmlindex de2aadaab5..e74355141b 100644--- a/registry/components/shutter-slam/shutter-slam.html+++ b/registry/components/shutter-slam/shutter-slam.html@@ -138,12 +138,24 @@var POLL_MS = 32;var POLL_TICKS = 250;var SWEEP_SELECTOR = "[" + SWEEP_ATTR + "]";- var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps"];+ var OPTION_KEYS = ["shutterAngle", "shutterPhase", "samplesPerFrame", "fps", "sharp"];// A copy is a deep clone, so the attribute rides along on the root AND on every marked// descendant. Any one left behind is swept as a target of its own, which clones again.var COPY_STRIP = [SWEEP_ATTR, "data-composition-id", "data-fps"];+ // sharp 0 hides a moving target through this marker rather than its own visibility,+ // which the author's timeline (autoAlpha) may be writing too.+ var HIDE_ATTR = "data-hf-motion-blur-hiding";++ function installHideRule() {+ if (document.getElementById("hf-mb-hide")) return;+ var rule = document.createElement("style");+ rule.id = "hf-mb-hide";+ rule.textContent = "[" + HIDE_ATTR + "]{visibility:hidden!important}";+ (document.head || document.documentElement).appendChild(rule);+ }+function stripAttrs(el) {for (var a = 0; a < COPY_STRIP.length; a++) el.removeAttribute(COPY_STRIP[a]);}@@ -230,6 +242,8 @@var shutterAngle = numOption(opts.shutterAngle, 720);var shutterPhase = numOption(opts.shutterPhase, -360);var requestedSamples = numOption(opts.samplesPerFrame, 16);+ var sharp = opts.sharp !== 0;+ if (!sharp) installHideRule();var samples = Number.isFinite(requestedSamples)? Math.max(2, Math.min(64, Math.round(requestedSamples))): 16;@@ -256,17 +270,23 @@// drops every `#id` rule that gave it size, colour and font. So each copy carries// its own resolved style inline. Chrome returns "" for a computed style's cssText,// so the declarations are enumerated rather than taken wholesale.- function resolvedStyles(source, out) {+ // Visibility is not frozen into a copy: its root takes the element's current one from+ // the group each frame, and a descendant keeps its own only where it differs from its+ // parent's. A target hidden at attach (autoAlpha) would otherwise never smear.+ function resolvedStyles(source, out, parentVisibility) {var cs = getComputedStyle(source);var text = "";for (var i = 0; i < cs.length; i++) {- text += cs[i] + ":" + cs.getPropertyValue(cs[i]) + ";";+ var value = cs.getPropertyValue(cs[i]);+ var inherited = parentVisibility === undefined || value === parentVisibility;+ if (cs[i] === "visibility" && inherited) continue;+ text += cs[i] + ":" + value + ";";}// A copy is a still of one instant. Left live, an inherited transition or// keyframe animation would carry it somewhere the timeline never sampled.out.push(text + "transition:none;animation:none;");for (var c = 0; c < source.children.length; c++) {- resolvedStyles(source.children[c], out);+ resolvedStyles(source.children[c], out, cs.getPropertyValue("visibility"));}return out;}@@ -315,7 +335,18 @@// that would walk the whole subtree once per copy; on resize it costs nothing// on a fixed-size render and keeps a live preview honest.function snapshot() {- var styles = resolvedStyles(el, []);+ // Read a target hidden right now (an autoAlpha entrance) as shown, so a descendant+ // hidden by its own rule still differs from it; the inline value goes back exactly.+ var hidden = getComputedStyle(el).visibility !== "visible";+ var inline = el.style.getPropertyValue("visibility");+ var priority = el.style.getPropertyPriority("visibility");+ if (hidden) el.style.setProperty("visibility", "visible", "important");+ var styles;+ try {+ styles = resolvedStyles(el, []);+ } finally {+ if (hidden) el.style.setProperty("visibility", inline, priority);+ }s.perspective = parentPerspective(el);for (var c = 0; c < clones.length; c++) {paintResolvedStyles(clones[c], styles, { i: 0 });@@ -379,6 +410,7 @@css: cs.transform,origin: cs.transformOrigin,opacity: cs.opacity,+ visibility: cs.visibility,parsed: parseTransform(cs.transform),};}@@ -414,6 +446,8 @@}state.forEach(function (s) {+ // Read the element as the timeline left it: the marker is this snippet's own.+ if (!sharp) s.el.removeAttribute(HIDE_ATTR);var current = readTransform(s.el);var moved = false;for (var i = 0; i < copies; i++) {@@ -444,12 +478,18 @@clone.style.transform =s.perspective + (s.samples[j].css === "none" ? "" : s.samples[j].css);}- // The copies are the element's own ink, so they have to carry its opacity too:+ // The copies are the element's own ink, so they carry its opacity and visibility:// a beat that moves and fades at once would otherwise leave a full-strength// smear behind a vanishing element. It rides the group, not the copies, whose// own opacity is the 1/N shutter weight.s.group.style.opacity = current.opacity;+ // Set only where the element differs from its parent: an explicit value would+ // outlive an ancestor that hides later, like a clip that has ended.+ var shared = getComputedStyle(s.el.parentNode).visibility;+ s.group.style.visibility =+ current.visibility === shared ? "" : current.visibility;s.group.style.display = "";+ if (!sharp) s.el.setAttribute(HIDE_ATTR, "");});}@@ -503,6 +543,9 @@if (bad !== null) return refuse(el, "names no such option: " + bad);var wrong = nonNumber(parsed);if (wrong !== null) return refuse(el, "needs a number for " + wrong);+ if (parsed.sharp !== undefined && parsed.sharp !== 0 && parsed.sharp !== 1) {+ return refuse(el, "needs 0 or 1 for sharp");+ }return parsed;}diff --git a/skills-manifest.json b/skills-manifest.jsonindex ab4d95cff4..581b3c40e8 100644--- a/skills-manifest.json+++ b/skills-manifest.json@@ -22,7 +22,7 @@"files": 29},"hyperframes-animation": {- "hash": "6af72990949385ca",+ "hash": "179715a416750b26","files": 122},"hyperframes-audio": {diff --git a/skills/hyperframes-animation/references/motion-blur.md b/skills/hyperframes-animation/references/motion-blur.mdindex e15b32ff41..1ae967a5e4 100644--- a/skills/hyperframes-animation/references/motion-blur.md+++ b/skills/hyperframes-animation/references/motion-blur.md@@ -61,14 +61,15 @@ that is already in the document, use the attribute.## Options-| Option | Default | Meaning |-| ----------------- | ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ |-| `shutterAngle` | 720 | Degrees of the frame interval the shutter is open. 720 is two frames, measured off a real After Effects export. 360 is one frame. 0 disables the smear |-| `shutterPhase` | -360 | Degrees the window start sits from the frame time. -360 centres the window on the frame |-| `samplesPerFrame` | 16 | Sub-intervals of the window, so this many plus one copies, each at 1 over this many opacity. Max 64 |-| `fps` | the `data-fps` of the target's own composition root, else 30 | Composition frame rate. Pass it explicitly when rendering with an fps override |--A key that is none of these four, and a value that is not a finite number, are+| Option | Default | Meaning |+| ----------------- | ------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |+| `shutterAngle` | 720 | Degrees of the frame interval the shutter is open. 720 is two frames, measured off a real After Effects export. 360 is one frame. 0 disables the smear |+| `shutterPhase` | -360 | Degrees the window start sits from the frame time. -360 centres the window on the frame |+| `samplesPerFrame` | 16 | Sub-intervals of the window, so this many plus one copies, each at 1 over this many opacity. Max 64 |+| `fps` | the `data-fps` of the target's own composition root, else 30 | Composition frame rate. Pass it explicitly when rendering with an fps override |+| `sharp` | 1 | 1 paints the element itself, crisp, over its smear. 0 hides it while it moves, leaving only the shutter average: a soft blur with no frame-time edge. It hides through a marker attribute, never the element's own visibility, so autoAlpha still works (an inline `visibility: visible !important` on it wins) |++A key that is none of these five, and a value that is not a finite number, areboth refused by name rather than read as defaults. `{"shutterAngle": "720deg"}`is a refusal, not a 720 degree shutter.@@ -87,7 +88,7 @@ nothing except where noted:| Console warns that no composition registered a timeline for an element | The element is outside every `data-composition-id`, or that composition never registers a timeline | Put it inside the composition's root, or register the timeline || Console warns the attribute is not JSON | Single quotes, unquoted keys, a trailing comma | Double-quoted JSON, or an empty attribute for defaults || Console warns the attribute is not a JSON object | `null`, a bare number, a quoted string, an array | An object, or an empty attribute for defaults |-| Console warns the attribute names no such option | A misspelled key, for example `samplesperframe` | Use one of the four names above, case-sensitive |+| Console warns the attribute names no such option | A misspelled key, for example `samplesperframe` | Use one of the five names above, case-sensitive || Console warns the attribute needs a number for an option | A quoted or unit-suffixed value, for example `"720deg"` | A bare JSON number || Console warns it cannot blur a target inside another target | Both an element and one of its ancestors carry the attribute | Mark one of them, the one that moves || Console warns one call cannot blur compositions at different frame rates | One `attachMotionBlur` call named elements in two compositions whose `data-fps` differ | One call per composition |