Files
Miguel ÁngelandMiguel Angel Simon Sierra 1ae2067b8d feat(catalog): put the variables panel back, on payloads (#3199)
* feat(catalog): put the variables panel back, on payloads

The panel drove its preview by loading an .html from docs/public, a type the
host does not publish, so it showed an empty frame in production and was
parked when the catalog was re-landed.

It now mounts the same JSON payload the plain player uses and re-mounts it as
values change, injecting them as window.__hfVariables into the composition head
before any of its scripts run, which is where the runtime reads overrides from.
Doing it in the markup rather than after load is what stops the composition
initialising with the wrong values first.

172 items with variables get the panel back; the playhead carries across a
change so a tweak mid-shot does not jump back to frame zero.

* fix(docs): drop the unused url form and the needless escapes

* fix(docs): the panel cannot reference a binding beside the export

* feat(catalog): make importing an SVG the obvious move

A reader arrives at this control with a shape, not with path data, and the
panel asked for the coordinates first. Import is now the primary action in a
drop target you can see is a drop target, and the raw path sits behind a
disclosure for anyone who wants it.

* feat(cli): let a fruitless catalog search report the gap

An agent that searches by meaning and finds nothing worth installing knows
something we do not: the name of a move the catalog is missing. There was no
way to tell us, so that knowledge was lost at the end of every run.

hyperframes feedback --search-miss "<query>" --wanted "<the move>" records it.
It carries no rating, so it never lands in the rating metric, and it is a
separate deliberate command rather than something catalog --query does on its
own: plain search still sends nothing, which is what the CLI promises.

--rating stops being required at the arg level, since a miss has no rating to
give. The check moved into the run body, where an absent one is now handled
rather than crashing on undefined.

* feat(cli): carry tuned variable values into the install snippet

Someone who tunes a block on its catalog page had no way to keep those values:
the install command was the same one everybody gets, and the tuning stayed on
the page.

hyperframes add <item> --vars '<json>' now prints a mount element carrying
data-variable-values, so the values land where the block is used.

They ride on the host rather than being written into the installed file. That
keeps the composition on disk byte-identical to the registry's, so a later
reinstall can still tell an edit from an update, and it lets two mounts of the
same block carry different values.

* fix(catalog): serve the item's own directory so runtime paths resolve

Some compositions assemble their asset URLs at run time —
"compositions/components/" + texture + ".png" for the texture masks, a font the
compiler pulled into _remote_media — and no scan of the markup can see a string
that does not exist until a script concatenates it. Those items either rendered
black or were dropped to a video that had never been uploaded.

Each item that needs it now has its prepared directory published, and its
payload carries a <base> pointing at it, so any relative path the composition
invents resolves. caption-texture renders its masks again, and
variable-font-flex has a preview at all for the first time: its MP4 and poster
are both 403.

Both layouts are published, because which one a composition asks for differs
per item, and a directory only earns that if it is under 2 MB. The 12 MB
texture sheet keeps the recorded video it already had.

* fix(catalog): let the variables panel actually drive the composition

Every control on the panel was inert. The values reached the composition and
nothing repainted, because the payload had already been compiled: compiling
inlines a mounted component and resolves its variables into the markup and CSS,
so by the time a reader turns a knob there is nothing left to change.

An item that declares variables now ships uncompiled, keeping the mount the
runtime loads at run time, which is the only state where data-variable-values
still means anything. The component travels inline as a data URI rather than a
sibling file, because .html is the one type the docs host will not publish. The
demo's own pinned values come off, so the reader's choices reach the mount
instead of losing to the values the demo picked to show itself off.

Measured on the rendered frame rather than the DOM: green rgb(98,207,144),
blue rgb(6,6,199), violet rgb(177,147,230), and back to green.

docs/public/catalog drops from 48 MB to 35 MB along the way, since an
uncompiled payload carries far less than an inlined one.

* feat(catalog): keep variable changes in the url

A reader who tuned a piece lost it on reload, and had nothing to send anyone.
The values now live in the query string, scoped by composition id so two links
never read each other,and only the ones that differ from the defaults are
written, so changing one knob gives a short URL rather than every variable
spelled out.

replaceState rather than pushState: dragging a slider should not leave a trail
of history entries. An unreadable value is ignored rather than thrown, so a
truncated or hand-edited link opens the piece at its defaults.

* fix(catalog): only rewrite the url when a value actually changed

* refactor(catalog): memoise the declared defaults on their content

* feat(catalog): offer an install command carrying the tuned values

The Install block is generated before anyone touches a knob, so it can only
ever print the plain command. Someone who spent a minute tuning a piece copied
it and got the defaults back.

The panel now carries its own command in the Snippet tab, with --vars holding
exactly the values that differ. An untouched piece still offers the same short
command, so nothing gets noisier for the common case.

* fix(catalog): a piece with nothing to render is a skip, not a failure

caption-blend-difference is a stylesheet and a paragraph of prose — a class you
add to your own captions, with no standalone scene to show. The generator
treated that as a build failure, so every run ended by reporting something
broken when nothing was.

It now reports the shape it is and keeps its recorded video, which is the only
honest preview such an item has. A genuine render failure still throws.

* fix(catalog): restore variables from the url on a cold load

A shared link opened at the defaults. The first render happens on the server,
where there is no window to read the query string from, and React then hydrates
against that markup and never revisits it — so the values only appeared once you
touched a control.

The URL is read again after mount, which is the first moment it exists. The
value is also escaped once now rather than twice: URLSearchParams already
decodes on the way out, and decoding a second time turned an SVG path full of
percent-escapes into something that no longer parsed, besides doubling the
length of every link.

* fix(catalog): mount the preview with the values a link carried

The frame was built from the declared defaults and the shared values were
posted to it afterwards, which is too late for anything the composition reads
once at init: a path arrived after the mark had already been drawn from the
default one, so a link looked right in the panel and wrong on screen.

* feat(catalog): the install command follows the values you tuned

Copying the Install line gave the plain command back, because that block is
generated before anyone touches a knob and had no way to know what changed. The
tuned command only existed in the panel Snippet tab, which is not where anyone
looks for it.

The line now reads the same query string the panel writes, so the two agree
without either component knowing the other exists, and a shared link carries the
right command too. replaceState fires no event, so the panel announces its own
writes.

* fix(catalog): send a text variable to the preview once it is finished

Every other control in the explorer reports a whole value on every event: a
slider at any position is a position, a swatch is a colour. A text field is
not. Typing v3 into a badge posted v first, so the preview remounted and
rendered a composition built from half a word.

The post now waits while a text field has focus and goes out when the edit is
committed, with Enter or by clicking away. The field itself is unchanged and
still tracks every keystroke.

---------

Co-authored-by: Miguel Angel Simon Sierra <miguelangelsi07@gmail.com>
2026-08-10 22:40:01 -04:00

1110 lines
46 KiB
Plaintext

---
title: "Segmentation Flood"
description: "Machine-vision read of a slotted subject: translucent accent segmentation masks flood on in quantized scanline steps, each region gets a thin bracket and mono label chip, a deterministic 2-frame HUD flicker rides the pass, then the labeled read settles clean."
---
import { InstallCommand } from "/snippets/install-command.jsx";
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
<VariablesExplorer
previewSrc="/public/catalog/components/segmentation-flood.json"
compositionId="segmentation-flood"
compositionSrc="compositions/components/segmentation-flood.html"
variables={[{"id":"regions","type":"string","role":"content","label":"Regions","description":"Comma-separated region labels; 2 to 4 are used, one translucent mask + bracket + mono chip each.","default":"Figure, Signal, Ground"},{"id":"flood_at","type":"number","role":"timing","label":"Flood at","description":"Seconds from mount start when the segmentation pass begins. Clamped so the pass and any exit stay inside the clip.","default":0.8},{"id":"flicker","type":"enum","role":"style","label":"Flicker","description":"Deterministic 2-frame HUD luminance toggle riding the flood pass.","default":"on","options":[{"value":"on","label":"On"},{"value":"off","label":"Off"}]},{"id":"accent","type":"enum","role":"style","label":"Accent","description":"Mask, bracket, and chip color: green rides --brand, blue rides --accent, violet rides --accent-2.","default":"green","options":[{"value":"green","label":"Green"},{"value":"blue","label":"Blue"},{"value":"violet","label":"Violet"}]},{"id":"exit","type":"enum","role":"timing","label":"Exit","description":"Optional departure. Default none: the labeled read holds until the frame cuts.","default":"none","options":[{"value":"none","label":"None"},{"value":"fade","label":"Fade"},{"value":"up","label":"Up"}]}]}
>
```html segmentation-flood.html
<!doctype html>
<!--
segmentation-flood: HyperFrames video primitive (product demo / AI)
A machine-vision read of a slotted subject. Translucent accent
segmentation masks FLOOD onto 2-4 regions in scanline steps: rows arrive
in 2-3 frame quanta (flood progress is quantized to frame steps before
any row is drawn), each region then gets a thin corner bracket and a mono
label chip; a subtle HUD flicker (a deterministic 2-frame luminance
toggle, a pure function of the frame index) rides the pass and stops the
instant the flood completes, settling to a clean labeled read.
Reference feel: gmunk segmentation sheets (red masks flooding under HUD
flicker), tokenized.
The subject is a SLOT. Callers place an inert template anywhere in the
HOST page (templates never render, and the runtime wipes the host clip's
own children on mount, so the slot lives at document level):
<template data-slot="segmentation-flood-subject"> ... </template>
Direct img/video children are stretched to cover the stage; arbitrary
HTML fills it. A missing slot falls back to a token scene: a surface
field with muted shapes seated where the default regions land, so the
read has something to read.
Variables (declared in data-composition-variables below):
- regions (comma label list, 2-4 used): one mask + bracket + chip per
label, flooding top-left to bottom-right in a staggered pass.
- flood_at (seconds): when the pass starts. Clamped so the whole pass
and any exit stay inside the clip.
- flicker ("on" | "off"): the 2-frame HUD luminance toggle.
- accent ("green" | "blue" | "violet"): green rides --brand, blue
rides --accent, violet rides --accent-2.
- exit ("none" | "fade" | "up", default none): frame roots own
transitions; the default holds the labeled read to the last pixel.
Envelope, fixed IN and OUT with elastic HOLD only (never timeScale):
IN ends when the last chip lands; HOLD = D - IN - OUT, truly still.
OUT_BASE = 0.45s only when exit != none.
Determinism (canvas 2D law): region geometry and per-region flood steps
come from one table computed once during synchronous timeline
construction from fixed LCG seed 0x5e6f100d. Every painted frame is a
pure function of (that table, the timeline's current time): the
timeline's onUpdate clears the canvas and redraws every mask row and the
flicker wash from scratch. Row arrival quantizes TIME to the region's
2-3 frame quantum, so a row lands whole and stays stable within its
step; the flicker is on exactly when floor(frame / 2) is odd inside the
flood window. No Math.random, no wall clock, no incremental state:
eventful seeks repaint identically in any order and either direction.
Mount contract: the runtime clones only this template. #root fills the
host box (no data-width/data-height, container-type: size, cqmin units),
is styled via #root only, and registers one paused timeline under the
LITERAL "segmentation-flood" key. All DOM state is set with explicit
endpoints (gsap.set + fromTo) so any seek order lands identical frames.
-->
<html
lang="en"
data-composition-id="segmentation-flood"
data-composition-duration="4.5"
data-composition-variables='[
{ "id": "regions", "type": "string", "role": "content", "label": "Regions", "description": "Comma-separated region labels; 2 to 4 are used, one translucent mask + bracket + mono chip each.", "default": "Figure, Signal, Ground" },
{ "id": "flood_at", "type": "number", "role": "timing", "label": "Flood at", "description": "Seconds from mount start when the segmentation pass begins. Clamped so the pass and any exit stay inside the clip.", "default": 0.8 },
{ "id": "flicker", "type": "enum", "role": "style", "label": "Flicker", "description": "Deterministic 2-frame HUD luminance toggle riding the flood pass.", "default": "on", "options": [{ "value": "on", "label": "On" }, { "value": "off", "label": "Off" }] },
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Mask, bracket, and chip color: green rides --brand, blue rides --accent, violet rides --accent-2.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Optional departure. Default none: the labeled read holds until the frame cuts.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
]'
>
<head>
<meta charset="UTF-8" />
<title>Segmentation Flood</title>
</head>
<body>
<template>
<div id="root" data-composition-id="segmentation-flood" data-duration="4.5" data-fps="30">
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
#root {
position: absolute;
inset: 0;
overflow: hidden;
container-type: size;
isolation: isolate;
color: var(--fg, #f8fafc);
font-family: var(--font-display, "Inter", system-ui, sans-serif);
pointer-events: none;
}
.sgf-clip {
position: absolute;
inset: 0;
overflow: hidden;
background: var(--bg, transparent);
}
.sgf-stage {
position: absolute;
inset: 0;
will-change: transform, opacity;
}
.sgf-subject {
position: absolute;
inset: 0;
overflow: hidden;
will-change: opacity;
}
.sgf-subject > img,
.sgf-subject > video {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.sgf-scene {
position: absolute;
inset: 0;
background: color-mix(in srgb, var(--surface, #14171c) 88%, var(--bg, #0b0c0e));
}
.sgf-shape {
position: absolute;
border: 0.16cqmin solid color-mix(in srgb, var(--border, #475569) 70%, transparent);
border-radius: var(--radius, 2cqmin);
background: color-mix(in srgb, var(--muted, #94a3b8) 16%, var(--surface, #14171c));
}
.sgf-shape.round {
border-radius: 50%;
}
.sgf-canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
.sgf-overlay {
position: absolute;
inset: 0;
}
.sgf-frame {
position: absolute;
will-change: opacity;
}
.sgf-corner {
position: absolute;
width: 2.6cqmin;
height: 2.6cqmin;
border: 0 solid var(--sgf-accent);
}
.sgf-corner.tl {
left: 0;
top: 0;
border-left-width: 0.28cqmin;
border-top-width: 0.28cqmin;
}
.sgf-corner.tr {
right: 0;
top: 0;
border-right-width: 0.28cqmin;
border-top-width: 0.28cqmin;
}
.sgf-corner.bl {
left: 0;
bottom: 0;
border-left-width: 0.28cqmin;
border-bottom-width: 0.28cqmin;
}
.sgf-corner.br {
right: 0;
bottom: 0;
border-right-width: 0.28cqmin;
border-bottom-width: 0.28cqmin;
}
.sgf-chip {
position: absolute;
display: inline-flex;
align-items: center;
gap: 0.9cqmin;
padding: 0.7cqmin 1.4cqmin;
border: 0.14cqmin solid
color-mix(in srgb, var(--sgf-accent) 60%, var(--border, #475569));
border-radius: calc(var(--radius, 2cqmin) * 0.4);
background: color-mix(in srgb, var(--bg, #0b0c0e) 78%, var(--sgf-accent));
color: var(--fg, #f8fafc);
font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
font-size: 1.9cqmin;
font-weight: 500;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
will-change: opacity, transform;
}
.sgf-chip-dot {
width: 0.9cqmin;
height: 0.9cqmin;
border-radius: 50%;
background: var(--sgf-accent);
}
</style>
<div
id="segmentation-flood-clip"
class="sgf-clip clip"
data-start="0"
data-duration="4.5"
data-track-index="0"
>
<div class="sgf-stage">
<div class="sgf-subject">
<div class="sgf-scene" aria-hidden="true"></div>
</div>
<canvas class="sgf-canvas" aria-hidden="true"></canvas>
<div class="sgf-overlay"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
"use strict";
var root = document.getElementById("root");
var stage = root.querySelector(".sgf-stage");
var subject = root.querySelector(".sgf-subject");
var scene = root.querySelector(".sgf-scene");
var canvas = root.querySelector(".sgf-canvas");
var overlay = root.querySelector(".sgf-overlay");
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
var labels = String(vars.regions == null ? "" : vars.regions)
.split(",")
.map(function (s) {
return s.trim();
})
.filter(Boolean)
.slice(0, 4);
if (labels.length < 2) labels = ["Figure", "Signal", "Ground"];
var floodAtRaw = parseFloat(vars.flood_at);
var flicker = vars.flicker !== "off";
var accentColors = {
green: "var(--brand, #71f5a7)",
blue: "var(--accent, #61a8ff)",
violet: "var(--accent-2, #c5a3ff)",
};
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
? vars.accent
: "green";
var exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
root.style.setProperty("--sgf-accent", accentColors[accent]);
// Region anchor cells (fractions of the stage), top-left to
// bottom-right so the staggered flood reads as one pass.
var anchors = [
{ x: 0.07, y: 0.11, w: 0.34, h: 0.36 },
{ x: 0.55, y: 0.08, w: 0.37, h: 0.4 },
{ x: 0.12, y: 0.56, w: 0.3, h: 0.33 },
{ x: 0.53, y: 0.58, w: 0.36, h: 0.31 },
];
// SLOT. Caller templates live at HOST DOCUMENT level.
var hostDoc = root.ownerDocument;
var slotTemplate = null;
try {
slotTemplate = hostDoc.querySelector(
'template[data-slot="segmentation-flood-subject"]',
);
} catch (error) {
slotTemplate = null;
}
if (slotTemplate) {
scene.remove();
subject.appendChild(hostDoc.importNode(slotTemplate.content, true));
} else {
// Default token scene: muted shapes seated inside the region
// anchors so the machine-vision read has content to read.
for (var s = 0; s < labels.length; s += 1) {
var cell = anchors[s];
var shape = hostDoc.createElement("div");
shape.className = s % 2 === 1 ? "sgf-shape round" : "sgf-shape";
shape.style.left = (cell.x + cell.w * 0.16) * 100 + "%";
shape.style.top = (cell.y + cell.h * 0.18) * 100 + "%";
shape.style.width = cell.w * 0.68 * 100 + "%";
shape.style.height = cell.h * 0.64 * 100 + "%";
scene.appendChild(shape);
}
}
// Envelope. The pass length is fixed by the region count; the
// start cue is clamped so pass + exit always fit.
var fps = 30;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4.5"));
var OUT = exit === "none" ? 0 : 0.45;
var STAGGER = 0.35;
var REGION_DUR = 1.0;
var CHIP_DUR = 0.3;
var passLen = STAGGER * (labels.length - 1) + REGION_DUR + CHIP_DUR;
var floodAt = isFinite(floodAtRaw) ? floodAtRaw : 0.8;
floodAt = Math.min(
Math.max(0.2, floodAt),
Math.max(0.2, duration - passLen - OUT - 0.1),
);
var floodEnd = floodAt + STAGGER * (labels.length - 1) + REGION_DUR;
var OUT_START = duration - OUT;
// Canvas raster basis, fixed once at mount (elastic root: the
// host box decides the resolution).
var dpr = Math.min(2, Math.max(1, Number(window.devicePixelRatio) || 1));
var box = root.getBoundingClientRect();
var cssW = Math.max(1, Math.round(box.width) || 640);
var cssH = Math.max(1, Math.round(box.height) || 360);
canvas.width = Math.round(cssW * dpr);
canvas.height = Math.round(cssH * dpr);
var ctx = canvas.getContext("2d");
// Resolve the accent token to a concrete color once at mount so
// canvas fills never depend on style recalc during seeks.
var probe = hostDoc.createElement("span");
probe.style.color = accentColors[accent];
root.appendChild(probe);
var maskColor = getComputedStyle(probe).color || "#71f5a7";
probe.remove();
// Seeded region table: geometry jitter + per-region flood
// quantum (2 or 3 frames) + scanline row count. Computed once;
// painted frames are pure functions of (table, time).
var regions = (function () {
var state = 0x5e6f100d;
function next() {
state = (Math.imul(1664525, state) + 1013904223) >>> 0;
return state / 4294967296;
}
var rows = [];
for (var i = 0; i < labels.length; i += 1) {
var a = anchors[i];
rows.push({
x: a.x + (next() - 0.5) * 0.02,
y: a.y + (next() - 0.5) * 0.02,
w: a.w * (0.94 + next() * 0.1),
h: a.h * (0.94 + next() * 0.1),
start: floodAt + STAGGER * i,
quantum: next() < 0.5 ? 2 : 3,
rows: 11 + Math.floor(next() * 4),
});
}
return rows;
})();
function clamp01(v) {
return v < 0 ? 0 : v > 1 ? 1 : v;
}
// Pure repaint: clear, then draw every mask's arrived rows and
// the flicker wash from (table, t). Row arrival quantizes time
// to the region's frame quantum, so rows land whole and hold
// stable within a step.
function paint(t) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < regions.length; i += 1) {
var r = regions[i];
var local = t - r.start;
if (local <= 0) continue;
var q = r.quantum / fps;
var quantized = Math.floor(local / q) * q;
var p = clamp01(quantized / REGION_DUR);
var visible = Math.min(r.rows, Math.floor(p * r.rows + 1e-6));
if (visible <= 0) continue;
var rx = r.x * canvas.width;
var rw = r.w * canvas.width;
var rowH = (r.h * canvas.height) / r.rows;
for (var k = 0; k < visible; k += 1) {
var leading = k === visible - 1 && visible < r.rows;
ctx.globalAlpha = leading ? 0.55 : 0.3;
ctx.fillStyle = maskColor;
// A hairline gap between rows keeps the scanline texture.
ctx.fillRect(
rx,
r.y * canvas.height + k * rowH,
rw,
Math.max(1, rowH - Math.max(1, dpr)),
);
}
}
// HUD flicker: pure function of the frame index, active only
// while the flood is in flight, gone the instant it settles.
if (flicker && t > floodAt && t < floodEnd) {
var frame = Math.floor(t * fps);
if (Math.floor(frame / 2) % 2 === 1) {
ctx.globalAlpha = 0.05;
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
}
ctx.globalAlpha = 1;
}
// Brackets + chips: DOM, positioned from the seeded table.
var frames = [];
var chips = [];
for (var i = 0; i < regions.length; i += 1) {
var r = regions[i];
var frameEl = hostDoc.createElement("div");
frameEl.className = "sgf-frame";
frameEl.style.left = r.x * 100 + "%";
frameEl.style.top = r.y * 100 + "%";
frameEl.style.width = r.w * 100 + "%";
frameEl.style.height = r.h * 100 + "%";
["tl", "tr", "bl", "br"].forEach(function (corner) {
var c = hostDoc.createElement("span");
c.className = "sgf-corner " + corner;
frameEl.appendChild(c);
});
overlay.appendChild(frameEl);
frames.push(frameEl);
var chip = hostDoc.createElement("div");
chip.className = "sgf-chip";
chip.style.left = r.x * 100 + "%";
// Chips sit above the region; bottom rows drop them inside
// the top edge so nothing leaves the stage.
if (r.y > 0.08) {
chip.style.top = "calc(" + r.y * 100 + "% - 3.9cqmin)";
} else {
chip.style.top = "calc(" + r.y * 100 + "% + 1cqmin)";
}
var dot = hostDoc.createElement("span");
dot.className = "sgf-chip-dot";
chip.appendChild(dot);
chip.appendChild(hostDoc.createTextNode(labels[i]));
overlay.appendChild(chip);
chips.push(chip);
}
gsap.set(stage, { opacity: 1, y: "0cqh" });
gsap.set(subject, { opacity: 0 });
var tl = gsap.timeline({
paused: true,
onUpdate: function () {
paint(tl.time());
},
});
// Anchor tween: an inert plain-object tween spanning the full
// authored duration so tl.time() covers [0, D] and onUpdate
// repaints the canvas on every eventful seek.
tl.to({ p: 0 }, { p: 1, duration: duration, ease: "none" }, 0);
// IN: the subject settles up quietly before the read begins.
tl.fromTo(
subject,
{ opacity: 0 },
{ opacity: 1, duration: 0.5, ease: "power2.out" },
0,
);
// Each region's bracket + chip land as its mask completes.
for (var i = 0; i < regions.length; i += 1) {
var done = regions[i].start + REGION_DUR;
tl.fromTo(
frames[i],
{ opacity: 0 },
{ opacity: 1, duration: 0.22, ease: "power2.out" },
done - 0.16,
);
tl.fromTo(
chips[i],
{ opacity: 0, y: "0.8cqh" },
{ opacity: 1, y: "0cqh", duration: CHIP_DUR, ease: "power2.out" },
done,
);
}
// HOLD: truly still; the flood is complete, the flicker window
// is closed, and the canvas repaints the same settled read.
// OUT: optional departure; exit none holds until the frame cuts.
if (exit === "up") {
tl.to(stage, { y: "-4cqh", duration: OUT, ease: "power2.in" }, OUT_START);
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
} else if (exit === "fade") {
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
}
tl.seek(0);
paint(0);
window.__timelines = window.__timelines || {};
window.__timelines["segmentation-flood"] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</VariablesExplorer>
## Install
<InstallCommand command="npx hyperframes add segmentation-flood" item="segmentation-flood" />
That writes one file: `compositions/components/segmentation-flood.html`.
## Paste it into your composition
Open `compositions/components/segmentation-flood.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.
## Variables
Every one of these has a default, so the piece works untouched. Set the ones you
want to change on the element:
| Variable | Default | Accepts | What it does |
| --- | --- | --- | --- |
| `regions` | `Figure, Signal, Ground` | string | Comma-separated region labels; 2 to 4 are used, one translucent mask + bracket + mono chip each. |
| `flood_at` | `0.8` | number | Seconds from mount start when the segmentation pass begins. Clamped so the pass and any exit stay inside the clip. |
| `flicker` | `on` | `on`, `off` | Deterministic 2-frame HUD luminance toggle riding the flood pass. |
| `accent` | `green` | `green`, `blue`, `violet` | Mask, bracket, and chip color: green rides --brand, blue rides --accent, violet rides --accent-2. |
| `exit` | `none` | `none`, `fade`, `up` | Optional departure. Default none: the labeled read holds until the frame cuts. |
Set them with `data-variable-values` on the element that mounts it. These are the
defaults, so this behaves exactly like the preview above until you change one:
```html wrap
<div
data-composition-id="segmentation-flood"
data-composition-src="compositions/components/segmentation-flood.html"
data-variable-values='{"regions":"Figure, Signal, Ground","flood_at":0.8,"flicker":"on","accent":"green","exit":"none"}'
></div>
```
## Source
<Accordion title={`segmentation-flood.html`}>
```html
<!doctype html>
<!--
segmentation-flood: HyperFrames video primitive (product demo / AI)
A machine-vision read of a slotted subject. Translucent accent
segmentation masks FLOOD onto 2-4 regions in scanline steps: rows arrive
in 2-3 frame quanta (flood progress is quantized to frame steps before
any row is drawn), each region then gets a thin corner bracket and a mono
label chip; a subtle HUD flicker (a deterministic 2-frame luminance
toggle, a pure function of the frame index) rides the pass and stops the
instant the flood completes, settling to a clean labeled read.
Reference feel: gmunk segmentation sheets (red masks flooding under HUD
flicker), tokenized.
The subject is a SLOT. Callers place an inert template anywhere in the
HOST page (templates never render, and the runtime wipes the host clip's
own children on mount, so the slot lives at document level):
<template data-slot="segmentation-flood-subject"> ... </template>
Direct img/video children are stretched to cover the stage; arbitrary
HTML fills it. A missing slot falls back to a token scene: a surface
field with muted shapes seated where the default regions land, so the
read has something to read.
Variables (declared in data-composition-variables below):
- regions (comma label list, 2-4 used): one mask + bracket + chip per
label, flooding top-left to bottom-right in a staggered pass.
- flood_at (seconds): when the pass starts. Clamped so the whole pass
and any exit stay inside the clip.
- flicker ("on" | "off"): the 2-frame HUD luminance toggle.
- accent ("green" | "blue" | "violet"): green rides --brand, blue
rides --accent, violet rides --accent-2.
- exit ("none" | "fade" | "up", default none): frame roots own
transitions; the default holds the labeled read to the last pixel.
Envelope, fixed IN and OUT with elastic HOLD only (never timeScale):
IN ends when the last chip lands; HOLD = D - IN - OUT, truly still.
OUT_BASE = 0.45s only when exit != none.
Determinism (canvas 2D law): region geometry and per-region flood steps
come from one table computed once during synchronous timeline
construction from fixed LCG seed 0x5e6f100d. Every painted frame is a
pure function of (that table, the timeline's current time): the
timeline's onUpdate clears the canvas and redraws every mask row and the
flicker wash from scratch. Row arrival quantizes TIME to the region's
2-3 frame quantum, so a row lands whole and stays stable within its
step; the flicker is on exactly when floor(frame / 2) is odd inside the
flood window. No Math.random, no wall clock, no incremental state:
eventful seeks repaint identically in any order and either direction.
Mount contract: the runtime clones only this template. #root fills the
host box (no data-width/data-height, container-type: size, cqmin units),
is styled via #root only, and registers one paused timeline under the
LITERAL "segmentation-flood" key. All DOM state is set with explicit
endpoints (gsap.set + fromTo) so any seek order lands identical frames.
-->
<html
lang="en"
data-composition-id="segmentation-flood"
data-composition-duration="4.5"
data-composition-variables='[
{ "id": "regions", "type": "string", "role": "content", "label": "Regions", "description": "Comma-separated region labels; 2 to 4 are used, one translucent mask + bracket + mono chip each.", "default": "Figure, Signal, Ground" },
{ "id": "flood_at", "type": "number", "role": "timing", "label": "Flood at", "description": "Seconds from mount start when the segmentation pass begins. Clamped so the pass and any exit stay inside the clip.", "default": 0.8 },
{ "id": "flicker", "type": "enum", "role": "style", "label": "Flicker", "description": "Deterministic 2-frame HUD luminance toggle riding the flood pass.", "default": "on", "options": [{ "value": "on", "label": "On" }, { "value": "off", "label": "Off" }] },
{ "id": "accent", "type": "enum", "role": "style", "label": "Accent", "description": "Mask, bracket, and chip color: green rides --brand, blue rides --accent, violet rides --accent-2.", "default": "green", "options": [{ "value": "green", "label": "Green" }, { "value": "blue", "label": "Blue" }, { "value": "violet", "label": "Violet" }] },
{ "id": "exit", "type": "enum", "role": "timing", "label": "Exit", "description": "Optional departure. Default none: the labeled read holds until the frame cuts.", "default": "none", "options": [{ "value": "none", "label": "None" }, { "value": "fade", "label": "Fade" }, { "value": "up", "label": "Up" }] }
]'
>
<head>
<meta charset="UTF-8" />
<title>Segmentation Flood</title>
</head>
<body>
<template>
<div id="root" data-composition-id="segmentation-flood" data-duration="4.5" data-fps="30">
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
#root {
position: absolute;
inset: 0;
overflow: hidden;
container-type: size;
isolation: isolate;
color: var(--fg, #f8fafc);
font-family: var(--font-display, "Inter", system-ui, sans-serif);
pointer-events: none;
}
.sgf-clip {
position: absolute;
inset: 0;
overflow: hidden;
background: var(--bg, transparent);
}
.sgf-stage {
position: absolute;
inset: 0;
will-change: transform, opacity;
}
.sgf-subject {
position: absolute;
inset: 0;
overflow: hidden;
will-change: opacity;
}
.sgf-subject > img,
.sgf-subject > video {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
}
.sgf-scene {
position: absolute;
inset: 0;
background: color-mix(in srgb, var(--surface, #14171c) 88%, var(--bg, #0b0c0e));
}
.sgf-shape {
position: absolute;
border: 0.16cqmin solid color-mix(in srgb, var(--border, #475569) 70%, transparent);
border-radius: var(--radius, 2cqmin);
background: color-mix(in srgb, var(--muted, #94a3b8) 16%, var(--surface, #14171c));
}
.sgf-shape.round {
border-radius: 50%;
}
.sgf-canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
.sgf-overlay {
position: absolute;
inset: 0;
}
.sgf-frame {
position: absolute;
will-change: opacity;
}
.sgf-corner {
position: absolute;
width: 2.6cqmin;
height: 2.6cqmin;
border: 0 solid var(--sgf-accent);
}
.sgf-corner.tl {
left: 0;
top: 0;
border-left-width: 0.28cqmin;
border-top-width: 0.28cqmin;
}
.sgf-corner.tr {
right: 0;
top: 0;
border-right-width: 0.28cqmin;
border-top-width: 0.28cqmin;
}
.sgf-corner.bl {
left: 0;
bottom: 0;
border-left-width: 0.28cqmin;
border-bottom-width: 0.28cqmin;
}
.sgf-corner.br {
right: 0;
bottom: 0;
border-right-width: 0.28cqmin;
border-bottom-width: 0.28cqmin;
}
.sgf-chip {
position: absolute;
display: inline-flex;
align-items: center;
gap: 0.9cqmin;
padding: 0.7cqmin 1.4cqmin;
border: 0.14cqmin solid
color-mix(in srgb, var(--sgf-accent) 60%, var(--border, #475569));
border-radius: calc(var(--radius, 2cqmin) * 0.4);
background: color-mix(in srgb, var(--bg, #0b0c0e) 78%, var(--sgf-accent));
color: var(--fg, #f8fafc);
font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, monospace);
font-size: 1.9cqmin;
font-weight: 500;
letter-spacing: 0.12em;
text-transform: uppercase;
white-space: nowrap;
will-change: opacity, transform;
}
.sgf-chip-dot {
width: 0.9cqmin;
height: 0.9cqmin;
border-radius: 50%;
background: var(--sgf-accent);
}
</style>
<div
id="segmentation-flood-clip"
class="sgf-clip clip"
data-start="0"
data-duration="4.5"
data-track-index="0"
>
<div class="sgf-stage">
<div class="sgf-subject">
<div class="sgf-scene" aria-hidden="true"></div>
</div>
<canvas class="sgf-canvas" aria-hidden="true"></canvas>
<div class="sgf-overlay"></div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
<script>
(function () {
"use strict";
var root = document.getElementById("root");
var stage = root.querySelector(".sgf-stage");
var subject = root.querySelector(".sgf-subject");
var scene = root.querySelector(".sgf-scene");
var canvas = root.querySelector(".sgf-canvas");
var overlay = root.querySelector(".sgf-overlay");
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
var labels = String(vars.regions == null ? "" : vars.regions)
.split(",")
.map(function (s) {
return s.trim();
})
.filter(Boolean)
.slice(0, 4);
if (labels.length < 2) labels = ["Figure", "Signal", "Ground"];
var floodAtRaw = parseFloat(vars.flood_at);
var flicker = vars.flicker !== "off";
var accentColors = {
green: "var(--brand, #71f5a7)",
blue: "var(--accent, #61a8ff)",
violet: "var(--accent-2, #c5a3ff)",
};
var accent = Object.prototype.hasOwnProperty.call(accentColors, vars.accent)
? vars.accent
: "green";
var exit = vars.exit === "fade" || vars.exit === "up" ? vars.exit : "none";
root.style.setProperty("--sgf-accent", accentColors[accent]);
// Region anchor cells (fractions of the stage), top-left to
// bottom-right so the staggered flood reads as one pass.
var anchors = [
{ x: 0.07, y: 0.11, w: 0.34, h: 0.36 },
{ x: 0.55, y: 0.08, w: 0.37, h: 0.4 },
{ x: 0.12, y: 0.56, w: 0.3, h: 0.33 },
{ x: 0.53, y: 0.58, w: 0.36, h: 0.31 },
];
// SLOT. Caller templates live at HOST DOCUMENT level.
var hostDoc = root.ownerDocument;
var slotTemplate = null;
try {
slotTemplate = hostDoc.querySelector(
'template[data-slot="segmentation-flood-subject"]',
);
} catch (error) {
slotTemplate = null;
}
if (slotTemplate) {
scene.remove();
subject.appendChild(hostDoc.importNode(slotTemplate.content, true));
} else {
// Default token scene: muted shapes seated inside the region
// anchors so the machine-vision read has content to read.
for (var s = 0; s < labels.length; s += 1) {
var cell = anchors[s];
var shape = hostDoc.createElement("div");
shape.className = s % 2 === 1 ? "sgf-shape round" : "sgf-shape";
shape.style.left = (cell.x + cell.w * 0.16) * 100 + "%";
shape.style.top = (cell.y + cell.h * 0.18) * 100 + "%";
shape.style.width = cell.w * 0.68 * 100 + "%";
shape.style.height = cell.h * 0.64 * 100 + "%";
scene.appendChild(shape);
}
}
// Envelope. The pass length is fixed by the region count; the
// start cue is clamped so pass + exit always fit.
var fps = 30;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4.5"));
var OUT = exit === "none" ? 0 : 0.45;
var STAGGER = 0.35;
var REGION_DUR = 1.0;
var CHIP_DUR = 0.3;
var passLen = STAGGER * (labels.length - 1) + REGION_DUR + CHIP_DUR;
var floodAt = isFinite(floodAtRaw) ? floodAtRaw : 0.8;
floodAt = Math.min(
Math.max(0.2, floodAt),
Math.max(0.2, duration - passLen - OUT - 0.1),
);
var floodEnd = floodAt + STAGGER * (labels.length - 1) + REGION_DUR;
var OUT_START = duration - OUT;
// Canvas raster basis, fixed once at mount (elastic root: the
// host box decides the resolution).
var dpr = Math.min(2, Math.max(1, Number(window.devicePixelRatio) || 1));
var box = root.getBoundingClientRect();
var cssW = Math.max(1, Math.round(box.width) || 640);
var cssH = Math.max(1, Math.round(box.height) || 360);
canvas.width = Math.round(cssW * dpr);
canvas.height = Math.round(cssH * dpr);
var ctx = canvas.getContext("2d");
// Resolve the accent token to a concrete color once at mount so
// canvas fills never depend on style recalc during seeks.
var probe = hostDoc.createElement("span");
probe.style.color = accentColors[accent];
root.appendChild(probe);
var maskColor = getComputedStyle(probe).color || "#71f5a7";
probe.remove();
// Seeded region table: geometry jitter + per-region flood
// quantum (2 or 3 frames) + scanline row count. Computed once;
// painted frames are pure functions of (table, time).
var regions = (function () {
var state = 0x5e6f100d;
function next() {
state = (Math.imul(1664525, state) + 1013904223) >>> 0;
return state / 4294967296;
}
var rows = [];
for (var i = 0; i < labels.length; i += 1) {
var a = anchors[i];
rows.push({
x: a.x + (next() - 0.5) * 0.02,
y: a.y + (next() - 0.5) * 0.02,
w: a.w * (0.94 + next() * 0.1),
h: a.h * (0.94 + next() * 0.1),
start: floodAt + STAGGER * i,
quantum: next() < 0.5 ? 2 : 3,
rows: 11 + Math.floor(next() * 4),
});
}
return rows;
})();
function clamp01(v) {
return v < 0 ? 0 : v > 1 ? 1 : v;
}
// Pure repaint: clear, then draw every mask's arrived rows and
// the flicker wash from (table, t). Row arrival quantizes time
// to the region's frame quantum, so rows land whole and hold
// stable within a step.
function paint(t) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < regions.length; i += 1) {
var r = regions[i];
var local = t - r.start;
if (local <= 0) continue;
var q = r.quantum / fps;
var quantized = Math.floor(local / q) * q;
var p = clamp01(quantized / REGION_DUR);
var visible = Math.min(r.rows, Math.floor(p * r.rows + 1e-6));
if (visible <= 0) continue;
var rx = r.x * canvas.width;
var rw = r.w * canvas.width;
var rowH = (r.h * canvas.height) / r.rows;
for (var k = 0; k < visible; k += 1) {
var leading = k === visible - 1 && visible < r.rows;
ctx.globalAlpha = leading ? 0.55 : 0.3;
ctx.fillStyle = maskColor;
// A hairline gap between rows keeps the scanline texture.
ctx.fillRect(
rx,
r.y * canvas.height + k * rowH,
rw,
Math.max(1, rowH - Math.max(1, dpr)),
);
}
}
// HUD flicker: pure function of the frame index, active only
// while the flood is in flight, gone the instant it settles.
if (flicker && t > floodAt && t < floodEnd) {
var frame = Math.floor(t * fps);
if (Math.floor(frame / 2) % 2 === 1) {
ctx.globalAlpha = 0.05;
ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, canvas.width, canvas.height);
}
}
ctx.globalAlpha = 1;
}
// Brackets + chips: DOM, positioned from the seeded table.
var frames = [];
var chips = [];
for (var i = 0; i < regions.length; i += 1) {
var r = regions[i];
var frameEl = hostDoc.createElement("div");
frameEl.className = "sgf-frame";
frameEl.style.left = r.x * 100 + "%";
frameEl.style.top = r.y * 100 + "%";
frameEl.style.width = r.w * 100 + "%";
frameEl.style.height = r.h * 100 + "%";
["tl", "tr", "bl", "br"].forEach(function (corner) {
var c = hostDoc.createElement("span");
c.className = "sgf-corner " + corner;
frameEl.appendChild(c);
});
overlay.appendChild(frameEl);
frames.push(frameEl);
var chip = hostDoc.createElement("div");
chip.className = "sgf-chip";
chip.style.left = r.x * 100 + "%";
// Chips sit above the region; bottom rows drop them inside
// the top edge so nothing leaves the stage.
if (r.y > 0.08) {
chip.style.top = "calc(" + r.y * 100 + "% - 3.9cqmin)";
} else {
chip.style.top = "calc(" + r.y * 100 + "% + 1cqmin)";
}
var dot = hostDoc.createElement("span");
dot.className = "sgf-chip-dot";
chip.appendChild(dot);
chip.appendChild(hostDoc.createTextNode(labels[i]));
overlay.appendChild(chip);
chips.push(chip);
}
gsap.set(stage, { opacity: 1, y: "0cqh" });
gsap.set(subject, { opacity: 0 });
var tl = gsap.timeline({
paused: true,
onUpdate: function () {
paint(tl.time());
},
});
// Anchor tween: an inert plain-object tween spanning the full
// authored duration so tl.time() covers [0, D] and onUpdate
// repaints the canvas on every eventful seek.
tl.to({ p: 0 }, { p: 1, duration: duration, ease: "none" }, 0);
// IN: the subject settles up quietly before the read begins.
tl.fromTo(
subject,
{ opacity: 0 },
{ opacity: 1, duration: 0.5, ease: "power2.out" },
0,
);
// Each region's bracket + chip land as its mask completes.
for (var i = 0; i < regions.length; i += 1) {
var done = regions[i].start + REGION_DUR;
tl.fromTo(
frames[i],
{ opacity: 0 },
{ opacity: 1, duration: 0.22, ease: "power2.out" },
done - 0.16,
);
tl.fromTo(
chips[i],
{ opacity: 0, y: "0.8cqh" },
{ opacity: 1, y: "0cqh", duration: CHIP_DUR, ease: "power2.out" },
done,
);
}
// HOLD: truly still; the flood is complete, the flicker window
// is closed, and the canvas repaints the same settled read.
// OUT: optional departure; exit none holds until the frame cuts.
if (exit === "up") {
tl.to(stage, { y: "-4cqh", duration: OUT, ease: "power2.in" }, OUT_START);
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
} else if (exit === "fade") {
tl.to(stage, { opacity: 0, duration: OUT, ease: "power2.in" }, OUT_START);
}
tl.seek(0);
paint(0);
window.__timelines = window.__timelines || {};
window.__timelines["segmentation-flood"] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</Accordion>
{/* hf:generated-footer */}
Tagged `motion-primitive` `product-demo` `ai` `hud` `canvas` `deterministic` `experiment`.
## Related topics
- [Browse the complete Catalog](/catalog)
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
- [Build a richer composition](/go-further)