Files
hyperframes/registry/blocks/cinemagraph/cinemagraph.html
04acbb4d9e feat(registry): add 4 community components (#4906)
* feat(registry): add cinemagraph — a still photograph with one living region

* feat(registry): add ai-answer-rank — a mock AI answer that re-ranks to put your brand in it

A 1080x1080, 9s block for answer-engine and AI-visibility marketing. A prompt
types into a chat card, the assistant answers with a ranked list of three picks,
then re-ranks: the promoted brand slides into its slot (brandRank 1-3), the picks
below step down, the third fades out of the list, and the brand row lands with
the one accent highlight and a drawn check. Monochrome placeholder UI; prompt,
lead-in, pick names, brand, rank, accent, ink and ground are variables.

* feat(registry): add caret swap text effect

* feat(registry): add pendulum-swing component

Add a motion-primitive component that hangs content from a fixed pivot and
lets it settle with a damped oscillation, like a hanging sign coming to rest
on its hook.

The swing rides a single unitless custom property (--hf-swing-angle) that the
timeline eases 1 -> 0, so only rotation animates and it stays sub-pixel under
the seek-by-frame capture engine. The demo drives it with a damped-oscillation
ease (a cosine inside an exponential decay, normalised to land exactly upright)
so the sign passes through center several times, each pass smaller, before it
rests.

Four enum variables: pivot (top-center/left/right), amplitude
(gentle/standard/wide), direction (right/left), tone (ink/paper/accent, each a
bg/fg pair to keep AA contrast on any frame). The snippet is recipe-only and
does not own its timeline; its demo carries the same variable declaration.

Ran npx hyperframes lint/validate on both files, regenerated registry.json via
scripts/generate-registry-items.ts and the docs via
scripts/generate-catalog-pages.ts.

* fix(registry): drop hand-added cinemagraph index entry; catalog-publish adds it

* style(registry): format pendulum-swing with oxfmt

* fix(registry): keep pendulum-swing demo caption clear of the swinging sign

* fix(registry): ship the ad-template editing contract for ai-answer-rank

---------

Co-authored-by: Carlos Miranda Levy <carlosmirandalevy@gmail.com>
Co-authored-by: tugrawork-creator <319556794+tugrawork-creator@users.noreply.github.com>
Co-authored-by: Akshar Patel <aksharcommit@gmail.com>
Co-authored-by: rottenpen <12029924+rottenpen@users.noreply.github.com>
2026-10-02 17:14:52 +00:00

299 lines
9.5 KiB
HTML
Vendored

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<!--
cinemagraph — a still photograph with ONE living region.
The frame is a frozen scene; a single masked window keeps moving — the classic
cinemagraph gesture: the camera stops, the world keeps breathing. The living
region here is the steam over a cup, drawn deterministically on a canvas from
the seek time alone, with a period that divides the duration, so the last
frame matches the first and the render loops seamlessly.
Using it with real media: keep the structure and swap the layers —
1. Put your looping <video> (or the animated source) as the BASE layer.
2. Put a freeze-frame still of it (an <img>) ABOVE, full-frame.
3. Move #cmg-window (the feathered mask) onto the still so the window
reveals the video beneath, and delete the placeholder scene + canvas.
One living region per frame. Two is a gif.
-->
<style>
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: #0b0e14;
overflow: hidden;
}
#root-cinemagraph {
position: relative;
width: 1920px;
height: 1080px;
overflow: hidden;
background: #0b0e14;
--hf-ink: #f8fafc;
}
/* ---- the still photograph (placeholder scene, monochrome ink ramp) ---- */
.cmg-photo {
position: absolute;
inset: 0;
}
/* window light falling across the scene */
.cmg-lightfall {
position: absolute;
inset: 0;
background: linear-gradient(
115deg,
color-mix(in srgb, var(--hf-ink) 8%, transparent) 0%,
transparent 46%
);
}
/* table surface */
.cmg-table {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 320px;
background: color-mix(in srgb, var(--hf-ink) 8%, transparent);
border-top: 1px solid color-mix(in srgb, var(--hf-ink) 14%, transparent);
}
/* window frame in the far wall */
.cmg-pane {
position: absolute;
left: 1210px;
top: 130px;
width: 420px;
height: 520px;
background: color-mix(in srgb, var(--hf-ink) 18%, transparent);
border: 1px solid color-mix(in srgb, var(--hf-ink) 14%, transparent);
}
.cmg-pane::before,
.cmg-pane::after {
content: "";
position: absolute;
background: color-mix(in srgb, var(--hf-ink) 14%, transparent);
}
.cmg-pane::before {
left: 50%;
top: 0;
bottom: 0;
width: 1px;
}
.cmg-pane::after {
top: 50%;
left: 0;
right: 0;
height: 1px;
}
/* saucer + cup, the photograph's subject */
.cmg-saucer {
position: absolute;
left: 760px;
bottom: 236px;
width: 400px;
height: 56px;
border-radius: 50%;
background: color-mix(in srgb, var(--hf-ink) 45%, transparent);
}
.cmg-cup {
position: absolute;
left: 830px;
bottom: 262px;
width: 260px;
height: 190px;
border-radius: 0 0 118px 118px;
background: color-mix(in srgb, var(--hf-ink) 72%, transparent);
}
.cmg-cup::after {
content: "";
position: absolute;
right: -64px;
top: 18px;
width: 88px;
height: 96px;
border: 22px solid color-mix(in srgb, var(--hf-ink) 72%, transparent);
border-radius: 50%;
}
.cmg-rim {
position: absolute;
left: 822px;
bottom: 436px;
width: 276px;
height: 34px;
border-radius: 50%;
background: color-mix(in srgb, var(--hf-ink) 45%, transparent);
}
/* a closed book beside the cup */
.cmg-book {
position: absolute;
left: 1180px;
bottom: 250px;
width: 330px;
height: 44px;
background: color-mix(in srgb, var(--hf-ink) 18%, transparent);
border: 1px solid color-mix(in srgb, var(--hf-ink) 14%, transparent);
transform: rotate(-2deg);
}
.cmg-book::after {
content: "";
position: absolute;
left: 14px;
right: 14px;
top: 12px;
height: 1px;
background: color-mix(in srgb, var(--hf-ink) 14%, transparent);
}
/* skeleton caption lines, bottom left — content lives here */
.cmg-line {
position: absolute;
left: 160px;
height: 22px;
border-radius: 11px;
background: color-mix(in srgb, var(--hf-ink) 18%, transparent);
}
/* ---- the ONE living region: a feathered window where steam moves ---- */
#cmg-window {
position: absolute;
left: 790px;
bottom: 430px;
width: 340px;
height: 420px;
-webkit-mask-image: radial-gradient(ellipse 50% 50% at 50% 55%, #000 55%, transparent 78%);
mask-image: radial-gradient(ellipse 50% 50% at 50% 55%, #000 55%, transparent 78%);
}
#cmg-canvas {
position: absolute;
inset: 0;
width: 340px;
height: 420px;
}
/* still vignette over everything, part of the photograph */
.cmg-vignette {
position: absolute;
inset: 0;
background: radial-gradient(
ellipse 78% 72% at 50% 46%,
transparent 62%,
rgba(4, 6, 10, 0.5) 100%
);
pointer-events: none;
}
</style>
</head>
<body>
<div
id="root-cinemagraph"
data-composition-id="cinemagraph"
data-start="0"
data-duration="10"
data-width="1920"
data-height="1080"
>
<div class="cmg-photo" id="cmg-photo">
<div class="cmg-lightfall"></div>
<div class="cmg-pane"></div>
<div class="cmg-table"></div>
<div class="cmg-saucer"></div>
<div class="cmg-cup"></div>
<div class="cmg-rim"></div>
<div class="cmg-book"></div>
<div class="cmg-line" style="bottom: 150px; width: 460px"></div>
<div class="cmg-line" style="bottom: 108px; width: 300px"></div>
</div>
<div id="cmg-window">
<canvas id="cmg-canvas" width="340" height="420"></canvas>
</div>
<div class="cmg-vignette"></div>
<div
id="drv-cinemagraph"
class="clip"
data-start="0"
data-duration="10"
data-track-index="0"
style="position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none"
></div>
</div>
<script>
(function () {
window.__timelines = window.__timelines || {};
// Seeded PRNG — never Math.random()
function mulberry32(a) {
return function () {
a |= 0;
a = (a + 0x6d2b79f5) | 0;
var t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
var rng = mulberry32(1897);
var DUR = 10;
// Each wisp cycles an integer number of times over DUR, so the frame at
// t = DUR equals the frame at t = 0 and the render loops seamlessly.
var WISPS = [];
for (var i = 0; i < 14; i++) {
WISPS.push({
x0: 90 + rng() * 160, // birth x inside the window
cycles: 1 + Math.floor(rng() * 2), // 1 or 2 full rises over DUR
phase: rng(), // where in its cycle it starts
sway: 14 + rng() * 26, // horizontal sway amplitude
swayFreq: 1 + Math.floor(rng() * 2), // integer — keeps the loop seam clean
width: 10 + rng() * 22, // wisp thickness
rise: 300 + rng() * 80, // how far it climbs before dissolving
alpha: 0.05 + rng() * 0.09,
});
}
var canvas = document.getElementById("cmg-canvas");
var ctx = canvas.getContext("2d");
var W = 340,
H = 420;
// State proxy — GSAP animates t, the render function reads it.
var st = { t: 0 };
function renderScene() {
ctx.clearRect(0, 0, W, H);
for (var i = 0; i < WISPS.length; i++) {
var w = WISPS[i];
// p in [0,1): this wisp's position in its own rise cycle
var p = (st.t / DUR) * w.cycles + w.phase;
p = p - Math.floor(p);
var y = H - 40 - p * w.rise;
var sway = Math.sin(2 * Math.PI * (p * w.swayFreq + w.phase)) * w.sway * p;
var x = w.x0 + sway;
// born faint, fullest mid-rise, dissolves at the top
var a = w.alpha * Math.sin(Math.PI * p);
var r = w.width * (0.7 + p * 1.6);
var g = ctx.createRadialGradient(x, y, 0, x, y, r * 2.4);
g.addColorStop(0, "rgba(248,250,252," + a.toFixed(4) + ")");
g.addColorStop(1, "rgba(248,250,252,0)");
ctx.fillStyle = g;
ctx.beginPath();
ctx.ellipse(x, y, r * 1.1, r * 2.2, sway * 0.004, 0, 2 * Math.PI);
ctx.fill();
}
}
var tl = gsap.timeline({ paused: true });
tl.to(st, { t: DUR, duration: DUR, ease: "none" }, 0);
window.__timelines["cinemagraph"] = tl;
// Render from the timeline only — no requestAnimationFrame.
tl.eventCallback("onUpdate", renderScene);
renderScene();
})();
</script>
</body>
</html>