mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-04 13:07:11 +00:00
* feat(catalog): add the seven 3D-motion pieces as installable registry blocks Each piece ships as a registry block with a CDN poster and preview, a live catalog detail page and its source. Scripts travel inside the catalog payload (shared vendor libraries fetched once, item scripts inline, the one HDR as a data URI) because the docs host only serves fonts, images and JSON. NO_ESSAY_COMMENTS_OK: the long comment blocks are in vendored libraries and the ported frost source under registry/blocks, not hand-written here. HF_MAX_NONLFS_KB=6000: four hosted texture PNGs under docs/public/catalog/items are runtime assets the docs host must serve as files. fallow skipped locally: it audits against origin/main and this branch is stacked on an older main. * chore(catalog): regenerate gallery data and nav after rebasing onto main * fix(catalog): read the install manifest through the bounded project reader * fix(catalog): a script the inliner missed fails the payload instead of shipping a dead URL * refactor(catalog): the leftover-script check reuses the reference finder * fix(catalog): frost and glass textures load from the CDN and the iteration presets are gone * chore(catalog): regenerate the frost and glass payloads and nav * fix(catalog): frost and glass textures are hosted through the registry url field, not hardcoded * chore(catalog): regenerate the frost and glass payloads against the hosted texture URLs * fix(catalog): the hosted-reference rewrite refuses a bare name it cannot safely replace * ci(catalog): verify changed catalog payloads in headless Chrome and check the docs catalog * feat(catalog): every item page follows the shared layout with a Tune panel and tabs * fix(catalog): let the texture-mask item host its masks so its tile plays live * chore(catalog): regenerate item pages, gallery data and the texture-mask payload * chore(catalog): regenerate item pages after merging main * fix(catalog): declared-only variables get the Tune panel, Code and Docs tabs capped * feat(catalog): give the blend-difference caption a demo scene so its tile plays live * chore(catalog): live payload for the blend-difference caption * perf(catalog): heavy 3d pieces compile and draw before ready, not on the first visible frame * feat(catalog): the avatar promo card hosts its videos, audio and fonts on the CDN * feat(catalog): the avatar promo card tile plays live from its CDN-hosted media * chore(catalog): the avatar promo card plays live, no allowlist left * chore(catalog): shorten two comment blocks * chore(catalog): trim first-party comment blocks to the comment-check limits * chore(catalog): shorten two frost source comments * fix(catalog): the Docs tab renders as prose again, and the detail page honours reduced motion Frame-mode pages carry no prose wrapper, and the detail component sat inside not-prose, so the Docs slot's headings, paragraphs, links and lists had no styling at all. The slots now carry their own prose classes and the chrome around them keeps not-prose. The recorded clip also gets the reduced-motion guard the docs-snippet check requires, and the generator reads stability from the source metadata type so the scripts typecheck passes. * fix(catalog): docs-tab paragraphs render as blocks Mintlify emits paragraphs as inline spans, so two paragraphs in the Docs slot ran together. * fix(ci): drop the duplicate docs_catalog job output git's line-based auto-merge silently duplicated the outputs key when main and this branch each added it on non-adjacent lines during the rebase; oxfmt's yaml parser rejects the repeated map key. * fix(catalog): close four CodeQL alerts in the frost source * chore(catalog): allowlist the avatar-promo-card CDN asset deletions, format sync-docs-catalog check-no-main-deletions.mjs was rejecting 11 local mp4/font files this branch already deleted in favor of CDN hosting; scripts/sync-docs-catalog.mjs had one line over the 100-col print width from an earlier edit in this branch. * fix(catalog): detail tabs use docs prose spacing, Install first; previews skip no-WebGPU runners * fix(catalog): the docs tab scrolls with the page instead of a capped inner box * refactor(catalog): split the payload asset and verify scripts into single-purpose helpers * refactor(catalog): split the preview generator into single-purpose helpers * ci(catalog): fail when the committed catalog differs from generator output The docs host serves the committed catalog and nothing regenerates it, so a stale copy shipped silently. The catalog payloads job now generates into a temp dir and compares it with the committed tree. * chore(catalog): regenerate docs/public/catalog with the refactored scripts One full regeneration from an empty output tree with the current scripts. The tree grows from 58.4 MB to 65.1 MB. Two hosted assets are about 2 MB each (an avatar png and a wav); the same bytes are already committed under assets/, so HF_MAX_NONLFS_KB is raised for this commit only. * fix(catalog): run the catalog script tests under the runner they are written for The rebase put three node:test files in the vitest half of test:scripts, where they report "No test suite found". They now sit in the node --test list. * fix(catalog): a WebGPU item without an adapter shows its recorded clip and says why * ci(catalog): the drift check runs from a committed fetch mirror with no network Generation now serves every font and CDN script fetch from scripts/catalog-fetch-mirror and fails when a fetch is not in it, even if the caller swallowed the error. CATALOG_FETCH_MIRROR=record refreshes the mirror from the live network. The docs_catalog filter also watches packages/core, packages/producer and the mirror, and the 13 re-hashed font files are listed in ALLOWED_DELETIONS. * chore(catalog): clean up the temp font cache and sort the mirror index without a locale * fix(catalog): hide Tune when the clip stands in, time out the adapter request, share one check * fix(catalog): the adapter probe survives a sync throw and a hang; test the clip guard * fix(catalog): keep the adapter probe inside the component, Mintlify evaluates only exports * fix(catalog): run the detail and page generator tests in CI; no Tune flash while probing WebGPU * docs(catalog): credit vendored libraries and make each SKILL.md list what the block installs CREDITS.md names every vendored dependency with its upstream and licence, and flags the two leaf textures whose origin is still to be confirmed. Each SKILL.md Files table now comes from the block manifest and its install and render paths point at compositions/<name>/. A test checks that every path a SKILL.md names is a manifest file that exists. * fix(catalog): a declared WebGPU item passes verify by its manifest tag, not by console wording verify-catalog-payloads forgave a missing adapter only by matching the markup and the message, which library-reported errors and widgets never satisfy. The webgpu tag in the item manifest is now the owner: a tagged item ignores its page and console errors, an untagged one gets no forgiveness, and a marker payload with no html is listed instead of crashing the run. * docs(catalog): correct the credits per block and guard the mount and render paths CREDITS.md states the three.js version and vendored-or-CDN status per block, adds d3-delaunay, Clipper on the CDN and the Google Fonts loads, and lists every texture with no known origin. The SKILL.md test now also checks the mount and render paths against the manifest composition. * test(catalog): read each block manifest once in the SKILL.md file test The two checks shared a copied manifest read, which fallow flagged as a clone with a high score. * fix(catalog): commit the hosted item files a gitignore rule kept out, and check git not the disk The compositions/ and *-ad/ ignore rules matched folder names under docs/public/catalog/items, so 33 hosted fonts, textures and marks were generated but never committed and would 404 on the docs host. The rules now have a negation for that tree and the files are added. The drift check read the checkout, where git-ignored files still exist, so it passed locally and failed only in CI. It now unpacks HEAD with git archive and compares that. * fix(catalog): a tile keeps its poster until the composition has painted * fix(catalog): a tagged WebGPU item forgives only the adapter-absent error, and test the wiring The manifest webgpu tag now decides whether an item may lack an adapter, and the error wording decides which lines are that absence. Any other page or console error on the item, and every failed request, still fails. The per-item decision is one exported function the tests drive, marker payloads are parsed by a tested helper, and the SKILL.md variable counts are checked against their tables (cuboid-carousel said forty-nine for forty). * fix(catalog): the pinned group's posters load eagerly at high priority * fix(catalog): type the tile reveal test so the scripts typecheck passes * fix(catalog): stop the adapter signature matching an unrelated failed adapter request failed to request .*adapter also matched errors about other adapters. It now matches only a request for the WebGPU adapter, so a tagged item cannot hide an unrelated failure behind it. * test(catalog): a tagged item still fails on an error about some other adapter * feat(catalog): the install command sits above the preview, as on the live catalog * fix(catalog): find the install slot through Mintlify's child wrapper * fix(docs): catalog copy buttons keep their size when the label swaps to Copied * refactor(docs): name the shown copy label once in the catalog copy button * fix(docs): primary catalog button keeps a readable label on hover and after copy * fix(docs): inset the catalog tab strip and tab content to match the boxed panels
890 lines
41 KiB
Plaintext
890 lines
41 KiB
Plaintext
---
|
|
title: "Shutter Slam"
|
|
description: "One word thrown through six single-property beats under integrated shutter blur — two translate slams, a scale punch, then a full turn about each axis — on the measured easing of the After Effects export the shutter model was fitted to"
|
|
mode: "frame"
|
|
---
|
|
|
|
import { CatalogDetail, CatalogSlot } from "/snippets/catalog-detail.jsx";
|
|
import { InstallCommand } from "/snippets/install-command.jsx";
|
|
|
|
<CatalogDetail
|
|
previewSrc="/public/catalog/components/shutter-slam.json"
|
|
compositionId="shutter-slam"
|
|
compositionSrc="compositions/components/shutter-slam.html"
|
|
title="Shutter Slam"
|
|
description="One word thrown through six single-property beats under integrated shutter blur — two translate slams, a scale punch, then a full turn about each axis — on the measured easing of the After Effects export the shutter model was fitted to"
|
|
variables={[{"id":"text","type":"string","role":"content","label":"Word","description":"The word driven through the six beats.","default":"MOTION"},{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Word color.","default":"green","options":[{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"blur","type":"enum","role":"motion","label":"Blur","description":"Integrate each frame over the shutter window, or capture one instant per frame.","default":"shutter","options":[{"value":"shutter","label":"Shutter"},{"value":"none","label":"None"}]},{"id":"cues","type":"string","role":"motion","label":"Cues","description":"Comma seconds from mount start for each of the six beats; empty keeps the authored rhythm.","default":""},{"id":"exit","type":"enum","role":"motion","label":"Exit","description":"How the word leaves.","default":"none","options":[{"value":"none","label":"None"},{"value":"fade","label":"Fade"},{"value":"up","label":"Up"}]}]}
|
|
meta={{"category":"Effects","badge":"Stable","codeLines":541}}
|
|
attribution={{"path":"registry/components/shutter-slam","tags":["effect","motion-blur","shutter","after-effects","slam","animation"]}}
|
|
hasCode
|
|
rawUrl="https://raw.githubusercontent.com/heygen-com/hyperframes/main/registry/components/shutter-slam/shutter-slam.html"
|
|
>
|
|
|
|
<CatalogSlot slot="code">
|
|
|
|
```html shutter-slam.html
|
|
<!doctype html>
|
|
<!--
|
|
shutter-slam: HyperFrames video primitive
|
|
|
|
One word thrown through six single-property beats, every frame integrated
|
|
over the camera shutter: two hard translate slams, a scale punch, then a
|
|
full turn about each of the three axes. It is the motion-blur primitive's
|
|
reference case — the beats are the ones measured off the After Effects
|
|
export the shutter model was fitted to, so every driver the model covers
|
|
(translate, scale, rotate, 3D rotate) is exercised in one mount.
|
|
|
|
Variables:
|
|
text: the slammed word
|
|
accent: green, blue, or violet word color
|
|
blur: shutter (integrated) or none (one instant per frame)
|
|
cues: comma seconds from mount start for each of the six beats
|
|
exit: none, fade, or up
|
|
|
|
Envelope, fixed beats with elastic HOLD:
|
|
BEATS = 5.97s at the authored rhythm (0.3s per slam, 0.6s per 3D turn,
|
|
0.73s for the Z turn)
|
|
HOLD = max(0, D - BEATS - OUT), the word at rest
|
|
OUT = 0.40s when exit is fade or up, else 0
|
|
If D is shorter than BEATS + OUT the beat clock compresses; the timeline
|
|
is never time-scaled.
|
|
|
|
Easing is power2.inOut because it measured best, not because it was the
|
|
default. A bezier fitted to the reference's own bbox centres looks like the
|
|
better curve on paper and renders worse: 1.3 dB down on the horizontal slam,
|
|
1.0 dB up on the vertical turn, 0.25 dB down over the clip. A blurred bbox
|
|
centre is the shutter window's average, not the instant, so on an
|
|
accelerating segment the fit is measuring its own blur.
|
|
|
|
Amplitudes are fractions of the host box (32.1cqw, 30.5cqh), so the slams
|
|
leave the frame on a wide mount exactly as far as they do on the reference.
|
|
The scale punch overflows on purpose; the clip crops it.
|
|
|
|
Mount contract: the runtime clones only this template. #root fills the host
|
|
box, establishes the container query basis, and has no data-width or
|
|
data-height. One paused timeline registers under the literal shutter-slam
|
|
key.
|
|
-->
|
|
<html
|
|
lang="en"
|
|
data-composition-id="shutter-slam"
|
|
data-composition-duration="6"
|
|
data-composition-variables='[
|
|
{ "id": "text", "type": "string", "role": "content", "label": "Word", "description": "The word driven through the six beats.", "default": "MOTION" },
|
|
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Word color.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
|
|
{ "id": "blur", "type": "enum", "role": "motion", "label": "Blur", "description": "Integrate each frame over the shutter window, or capture one instant per frame.", "default": "shutter", "options": [{ "value": "shutter", "label": "Shutter" }, { "value": "none", "label": "None" }] },
|
|
{ "id": "cues", "type": "string", "role": "motion", "label": "Cues", "description": "Comma seconds from mount start for each of the six beats; empty keeps the authored rhythm.", "default": "" },
|
|
{ "id": "exit", "type": "enum", "role": "motion", "label": "Exit", "description": "How the word leaves.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
|
|
]'
|
|
>
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Shutter Slam</title>
|
|
</head>
|
|
<body>
|
|
<template>
|
|
<div id="root" data-composition-id="shutter-slam" data-duration="6" data-fps="30">
|
|
<style>
|
|
*,
|
|
*::before,
|
|
*::after {
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
#root {
|
|
position: absolute;
|
|
inset: 0;
|
|
overflow: hidden;
|
|
container-type: size;
|
|
isolation: isolate;
|
|
font-family: var(--font-display, Inter, system-ui, sans-serif);
|
|
pointer-events: none;
|
|
}
|
|
|
|
.ss-clip {
|
|
position: absolute;
|
|
inset: 0;
|
|
width: 100cqw;
|
|
height: 100cqh;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* The turns need a perspective ancestor, and the blur reads its
|
|
perspective off the word's own parent, so the stage that carries
|
|
it must be the word's direct parent. */
|
|
.ss-stage {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: grid;
|
|
place-items: center;
|
|
perspective: 104cqw;
|
|
}
|
|
|
|
.ss-word {
|
|
color: var(--ss-accent, #71f5a7);
|
|
font-size: var(--ss-font-size, min(14cqw, 26cqh));
|
|
font-weight: 900;
|
|
line-height: 1;
|
|
letter-spacing: -0.02em;
|
|
white-space: nowrap;
|
|
transform-origin: 50% 50%;
|
|
will-change: transform;
|
|
}
|
|
</style>
|
|
|
|
<div
|
|
id="shutter-slam-clip"
|
|
class="ss-clip clip"
|
|
data-start="0"
|
|
data-duration="6"
|
|
data-track-index="0"
|
|
>
|
|
<div class="ss-stage">
|
|
<div class="ss-word" id="shutter-slam-word" role="heading" aria-level="1"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
|
<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"];
|
|
|
|
// 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"];
|
|
|
|
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 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.
|
|
function resolvedStyles(source, out) {
|
|
var cs = getComputedStyle(source);
|
|
var text = "";
|
|
for (var i = 0; i < cs.length; i++) {
|
|
text += cs[i] + ":" + cs.getPropertyValue(cs[i]) + ";";
|
|
}
|
|
// 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);
|
|
}
|
|
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() {
|
|
var styles = resolvedStyles(el, []);
|
|
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,
|
|
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) {
|
|
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 have to carry its opacity too:
|
|
// 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;
|
|
s.group.style.display = "";
|
|
});
|
|
}
|
|
|
|
// 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);
|
|
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 root = document.getElementById("root");
|
|
var word = root.querySelector(".ss-word");
|
|
var vars =
|
|
window.__hyperframes && window.__hyperframes.getVariables
|
|
? window.__hyperframes.getVariables()
|
|
: {};
|
|
|
|
var text = vars.text == null ? "MOTION" : String(vars.text);
|
|
var accentColors = {
|
|
green: "var(--brand, #71f5a7)",
|
|
blue: "var(--accent, #61a8ff)",
|
|
violet: "var(--accent-2, #b895ff)",
|
|
};
|
|
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
|
|
? vars.accent
|
|
: "green";
|
|
var blurred = vars.blur !== "none";
|
|
var exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
|
|
|
|
root.style.setProperty("--ss-accent", accentColors[accent]);
|
|
word.textContent = text;
|
|
|
|
// One em per character keeps any word inside the box at rest, which is what
|
|
// the slam amplitudes are measured against; the scale punch is meant to
|
|
// overflow and the clip crops it.
|
|
var fittedCqw = Math.min(14, 76 / Math.max(1, Array.from(text).length));
|
|
root.style.setProperty("--ss-font-size", "min(" + fittedCqw.toFixed(3) + "cqw, 26cqh)");
|
|
|
|
// Measured best, not defaulted. A bezier fitted to the reference's own bbox
|
|
// centres renders 0.25 dB worse over the clip, because a blurred bbox centre
|
|
// is the shutter window's average rather than the instant. See the header.
|
|
var EASE = "power2.inOut";
|
|
var SLAM_X = 32.1; // cqw, the reference's 617 px on a 1920 px frame
|
|
var SLAM_Y = 30.5; // cqh, its 329 px on a 1080 px frame
|
|
var SLAM = 0.3;
|
|
var TURN = 0.6;
|
|
var TURN_Z = 0.733;
|
|
// Authored start of each beat.
|
|
var CUES_BASE = [0, 1.2, 2.4, 3.7, 4.5, 5.233];
|
|
var BEATS_BASE = CUES_BASE[5] + TURN_Z;
|
|
var OUT_BASE = exit === "none" ? 0 : 0.4;
|
|
|
|
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "6"));
|
|
var baseTotal = BEATS_BASE + OUT_BASE;
|
|
var beatScale = duration < baseTotal ? duration / baseTotal : 1;
|
|
|
|
var slam = SLAM * beatScale;
|
|
var turn = TURN * beatScale;
|
|
var turnZ = TURN_Z * beatScale;
|
|
var out = OUT_BASE * beatScale;
|
|
// How long each beat runs, in beat order.
|
|
var LENGTHS = [slam * 4, slam * 4, slam * 4, turn, turn, turnZ];
|
|
|
|
// An authored cue replaces the rhythm rather than scaling it, so a beat locked
|
|
// to narration lands where the narration does. A missing or unreadable entry
|
|
// keeps its authored start; one that would run its beat past the mount is
|
|
// pulled back to end on the last frame, since past the end it never renders.
|
|
var authored = String(vars.cues == null ? "" : vars.cues)
|
|
.split(",")
|
|
.map(function (part) {
|
|
return parseFloat(part.trim());
|
|
});
|
|
var cues = CUES_BASE.map(function (base, index) {
|
|
var value = authored[index];
|
|
if (!Number.isFinite(value)) return base * beatScale;
|
|
return Math.min(Math.max(value, 0), Math.max(0, duration - out - LENGTHS[index]));
|
|
});
|
|
|
|
var tl = gsap.timeline({ paused: true, defaults: { ease: EASE } });
|
|
|
|
// Beat 1 — translate X, out and back twice.
|
|
tl.to(word, { x: SLAM_X + "cqw", duration: slam }, cues[0])
|
|
.to(word, { x: -SLAM_X + "cqw", duration: slam }, cues[0] + slam)
|
|
.to(word, { x: SLAM_X + "cqw", duration: slam }, cues[0] + slam * 2)
|
|
.to(word, { x: 0, duration: slam }, cues[0] + slam * 3);
|
|
|
|
// Beat 2 — translate Y, up first.
|
|
tl.to(word, { y: -SLAM_Y + "cqh", duration: slam }, cues[1])
|
|
.to(word, { y: SLAM_Y + "cqh", duration: slam }, cues[1] + slam)
|
|
.to(word, { y: -SLAM_Y + "cqh", duration: slam }, cues[1] + slam * 2)
|
|
.to(word, { y: 0, duration: slam }, cues[1] + slam * 3);
|
|
|
|
// Beat 3 — scale punch, up then down then up.
|
|
tl.to(word, { scale: 4.04, duration: slam }, cues[2])
|
|
.to(word, { scale: 0.466, duration: slam }, cues[2] + slam)
|
|
.to(word, { scale: 4.04, duration: slam }, cues[2] + slam * 2)
|
|
.to(word, { scale: 1, duration: slam }, cues[2] + slam * 3);
|
|
|
|
// Beats 4 to 6 — one full turn about each axis. A full turn ends where it
|
|
// started, so each is a single tween rather than an out-and-back pair.
|
|
tl.to(word, { rotationX: 360, duration: turn }, cues[3]);
|
|
tl.to(word, { rotationY: 360, duration: turn }, cues[4]);
|
|
tl.to(word, { rotation: 360, duration: turnZ }, cues[5]);
|
|
|
|
var beatsEnd = Math.max.apply(
|
|
null,
|
|
cues.map(function (cue, index) {
|
|
return cue + LENGTHS[index];
|
|
}),
|
|
);
|
|
var outStart = Math.max(beatsEnd, duration - out);
|
|
|
|
if (exit !== "none") {
|
|
var leaving = { opacity: 0, duration: out, ease: "power2.in" };
|
|
if (exit === "up") leaving.y = "-12cqh";
|
|
tl.to(word, leaving, outStart);
|
|
}
|
|
|
|
// Seeks past the last tween must still reach the blur's tracker, so the
|
|
// timeline runs to the mount's full duration.
|
|
tl.set(document.body, {}, duration);
|
|
|
|
// After every tween, before registration: the tracker tween the blur adds
|
|
// needs the timeline's final duration.
|
|
if (blurred) attachMotionBlur(word, tl, { fps: 30 });
|
|
|
|
tl.seek(0);
|
|
window.__timelines = window.__timelines || {};
|
|
window.__timelines["shutter-slam"] = tl;
|
|
})();
|
|
</script>
|
|
</div>
|
|
</template>
|
|
</body>
|
|
</html>
|
|
```
|
|
|
|
</CatalogSlot>
|
|
|
|
<CatalogSlot slot="install">
|
|
|
|
<InstallCommand command="npx hyperframes add shutter-slam" item="shutter-slam" />
|
|
|
|
That writes one file: `compositions/components/shutter-slam.html`.
|
|
|
|
</CatalogSlot>
|
|
|
|
<CatalogSlot slot="docs">
|
|
|
|
## Paste it into your composition
|
|
|
|
Open `compositions/components/shutter-slam.html` and copy what is inside into your own composition.
|
|
|
|
A component has no size or duration of its own. It takes both from the composition
|
|
you paste it into.
|
|
|
|
{/* hf:generated-footer */}
|
|
|
|
Tagged `effect` `motion-blur` `shutter` `after-effects` `slam` `animation`.
|
|
|
|
## Related topics
|
|
|
|
- [Browse the complete Catalog](/catalog)
|
|
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
|
|
- [Build a richer composition](/go-further)
|
|
|
|
</CatalogSlot>
|
|
|
|
</CatalogDetail>
|