Files
hyperframes/docs/catalog/components/camera-scan-gate.mdx
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

1118 lines
43 KiB
Plaintext

---
title: "Camera Scan Gate"
description: "A camera and QR recognition moment with a viewfinder sweep, bracket lock, confirmation pulse, and verified next beat."
---
import { InstallCommand } from "/snippets/install-command.jsx";
import { VariablesExplorer } from "/snippets/variables-explorer.jsx";
<VariablesExplorer
previewSrc="/public/catalog/components/camera-scan-gate.json"
compositionId="camera-scan-gate"
compositionSrc="compositions/components/camera-scan-gate.html"
variables={[{"id":"scanColor","type":"string","role":"style","label":"Scan color","description":"Any CSS color value used by the scan line and recognition glow.","default":"var(--brand)"},{"id":"targetLabel","type":"string","role":"content","label":"Target label","description":"Confirmation label revealed at recognition lock. Blank hides the line.","default":"Verified"},{"id":"sweepSpeed","type":"number","role":"timing","label":"Sweep speed","description":"Speed multiplier for the scan sweep phase only.","default":1,"min":0.8,"max":1.6,"step":0.1,"unit":"x"}]}
>
```html camera-scan-gate.html
<!doctype html>
<!--
camera-scan-gate -- HyperFrames video primitive (ui-props / interaction / demonstrate)
Concept: a camera viewfinder scans once, tightens its four L-shaped corner
brackets onto a detected target, then confirms recognition with a pulse,
check flash, and target label. One mechanic, one job: demonstrate the causal
scan -> lock -> confirmation gate that unlocks a product's next beat.
Compiled-from evidence: SIM fixture; MOBILE mobile-inventory (scan-to-onboard
and scan-to-pay moments in the video-primitives candidates card).
Use when: a mobile product scene needs a camera, QR, identity, or payment
recognition moment whose successful lock causes the following action. Skip
it for passive camera decoration or a generic loading state.
Variables (declared in data-composition-variables below):
- scanColor (string, default "var(--brand)"): any CSS color value used by
the scan line, lock brackets, and confirmation glow.
- targetLabel (string, default "Verified"): label revealed at lock. Empty
string hides the label line entirely.
- sweepSpeed (number, default 1, range 0.8 to 1.6): scan sweep speed only.
It changes the sweep start while its landing sync point stays fixed.
Envelope (fixed IN/OUT, elastic HOLD only, never gsap.timeScale()):
IN_BASE = 1.05s stage settles, sweep lands, then recognition locks
HOLD = elastic = max(0, D - (IN_BASE + OUT_BASE)); a faint finite
frame glow breathes, or remains still when HOLD == 0
OUT_BASE = 0.50s resolved gate releases with a short fade
If D < IN_BASE + OUT_BASE, IN and OUT scale down together so IN + OUT == D
and HOLD == 0.
Sync points (fixed offsets into IN, never inside elastic HOLD):
- scan-landed: 0.50s into unscaled IN, the --ease-standard sweep completes
- recognition-lock: 0.68s into unscaled IN, brackets tighten with
--ease-overshoot while confirmation and the target label fire
Both offsets scale proportionally only when the full envelope compresses.
Sound cue: a soft recognition chime fires at recognition-lock. The primitive
never plays audio itself. It dispatches an `hf:sfx` CustomEvent
({ id: "lock-chime", t: LOCK_AT }) for the host mix stage to route.
Mount contract: this file is a MOUNTABLE SUB-COMPOSITION, not a standalone
composition. A host loads it via data-composition-src; the runtime clones
only <template> contents, so all live style, markup, and script stays inside
the template. The root has no data-width/data-height and fills the host box
with position:absolute, inset:0, and container-type:size. It is styled by
#root because mounted CSS scoping would stop a root-class selector from
matching the root itself. The hardcoded "camera-scan-gate" composition id
is required because the mounted flattening step strips data-composition-id
before this script registers its timeline. Variables are read through
window.__hyperframes.getVariables(), which owns declared defaults merged
with per-instance host overrides after mounting.
-->
<html
lang="en"
data-composition-variables='[
{ "id": "scanColor", "type": "string", "role": "style", "label": "Scan color", "description": "Any CSS color value used by the scan line and recognition glow.", "default": "var(--brand)" },
{ "id": "targetLabel", "type": "string", "role": "content", "label": "Target label", "description": "Confirmation label revealed at recognition lock. Blank hides the line.", "default": "Verified" },
{ "id": "sweepSpeed", "type": "number", "role": "timing", "label": "Sweep speed", "description": "Speed multiplier for the scan sweep phase only.", "default": 1, "min": 0.8, "max": 1.6, "step": 0.1, "unit": "x" }
]'
>
<head>
<meta charset="UTF-8" />
<title>Camera Scan Gate</title>
<!-- Metadata only. The loader reads variable declarations from this html
element, while the mount runtime discards everything outside the
template. -->
</head>
<body>
<template>
<div
id="root"
data-composition-id="camera-scan-gate"
data-start="0"
data-duration="4"
data-fps="30"
>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
/* INVARIANT: the host owns dimensions. #root fills that box and
establishes the cqw/cqh basis for every visible measurement. */
#root {
position: absolute;
inset: 0;
container-type: size;
isolation: isolate;
overflow: hidden;
color: var(--fg, #f8fafc);
font-family: var(--font-body, Inter, system-ui, sans-serif);
}
.csg-clip {
position: relative;
width: 100%;
height: 100%;
display: grid;
place-items: center;
overflow: hidden;
background: var(--bg, #0b1120);
}
.csg-stage {
position: relative;
width: min(64cqw, 76cqh);
aspect-ratio: 1;
opacity: 0;
}
/* EDIT ZONE: the outer viewfinder is a square so one centered scale
operation tightens all four brackets onto the target equally. */
.csg-frame,
.csg-corner-layer,
.csg-scan-window {
position: absolute;
inset: 0;
}
.csg-frame {
border: 0.16cqw solid color-mix(in srgb, var(--border, #334155) 74%, transparent);
border-radius: var(--space-2, 2.4cqw);
background: color-mix(in srgb, var(--surface, #1e293b) 34%, transparent);
box-shadow: inset 0 0 5cqw color-mix(in srgb, var(--bg, #0b1120) 60%, transparent);
}
.csg-grid {
position: absolute;
inset: 0;
border-radius: inherit;
background-image:
linear-gradient(
to right,
transparent 33%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 33% 33.25%,
transparent 33.25% 66.5%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 66.5% 66.75%,
transparent 66.75%
),
linear-gradient(
to bottom,
transparent 33%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 33% 33.25%,
transparent 33.25% 66.5%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 66.5% 66.75%,
transparent 66.75%
);
opacity: 0.55;
}
.csg-ambient {
position: absolute;
inset: -4%;
border: 0.45cqw solid
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 48%, transparent);
border-radius: var(--space-3, 3.2cqw);
box-shadow: 0 0 4.5cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 38%, transparent);
opacity: 0;
}
.csg-corner-layer {
transform-origin: center;
z-index: 3;
}
.csg-corner {
position: absolute;
width: 18%;
height: 18%;
border-color: var(--csg-scan-color, var(--brand, #22c55e));
border-style: solid;
filter: drop-shadow(
0 0 0.9cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 56%, transparent)
);
}
.csg-corner-tl {
top: 0;
left: 0;
border-width: 0.65cqw 0 0 0.65cqw;
border-radius: var(--space-2, 2.4cqw) 0 0;
}
.csg-corner-tr {
top: 0;
right: 0;
border-width: 0.65cqw 0.65cqw 0 0;
border-radius: 0 var(--space-2, 2.4cqw) 0 0;
}
.csg-corner-br {
right: 0;
bottom: 0;
border-width: 0 0.65cqw 0.65cqw 0;
border-radius: 0 0 var(--space-2, 2.4cqw);
}
.csg-corner-bl {
bottom: 0;
left: 0;
border-width: 0 0 0.65cqw 0.65cqw;
border-radius: 0 0 0 var(--space-2, 2.4cqw);
}
.csg-scan-window {
z-index: 2;
inset: 3.5%;
overflow: hidden;
}
.csg-sweep {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
.csg-scan-line {
position: absolute;
inset: 0 0 auto;
width: 100%;
height: 0.38cqh;
border-radius: 999cqw;
background: var(--csg-scan-color, var(--brand, #22c55e));
box-shadow:
0 0 1.2cqw var(--csg-scan-color, var(--brand, #22c55e)),
0 1.8cqh 3.6cqh
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 42%, transparent);
}
.csg-target {
position: absolute;
z-index: 1;
width: 60%;
height: 60%;
top: 20%;
left: 20%;
border: 0.2cqw solid
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 65%, transparent);
border-radius: var(--space-2, 2.4cqw);
background: color-mix(
in srgb,
var(--csg-scan-color, var(--brand, #22c55e)) 7%,
transparent
);
opacity: 0;
}
.csg-confirmation {
position: absolute;
z-index: 4;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: var(--space-2, 2.2cqh);
}
.csg-pulse {
position: absolute;
width: 30%;
aspect-ratio: 1;
border: 0.42cqw solid var(--csg-scan-color, var(--brand, #22c55e));
border-radius: 50%;
box-shadow: 0 0 4.5cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 58%, transparent);
opacity: 0;
}
.csg-check {
display: block;
width: 8.5%;
height: 15%;
margin-top: -5%;
border-right: 0.8cqw solid var(--csg-scan-color, var(--brand, #22c55e));
border-bottom: 0.8cqw solid var(--csg-scan-color, var(--brand, #22c55e));
filter: drop-shadow(
0 0 1.1cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 65%, transparent)
);
opacity: 0;
transform: rotate(45deg);
}
.csg-label {
min-width: 34%;
padding: var(--space-1, 1cqh) var(--space-3, 3cqw);
border: 0.14cqw solid
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 48%, transparent);
border-radius: 999cqw;
background: color-mix(in srgb, var(--surface, #1e293b) 88%, transparent);
color: var(--fg, #f8fafc);
font-family: var(--font-display, Inter, system-ui, sans-serif);
font-size: clamp(2cqh, 2.8cqw, 3.3cqh);
font-weight: 760;
letter-spacing: 0.035em;
line-height: 1.1;
text-align: center;
opacity: 0;
}
.csg-label:empty {
display: none;
}
</style>
<div
id="camera-scan-gate-clip"
class="csg-clip clip"
data-start="0"
data-duration="4"
data-track-index="0"
>
<div class="csg-stage" role="img" aria-label="Camera recognition scanner">
<div class="csg-frame">
<div class="csg-grid" aria-hidden="true"></div>
</div>
<div class="csg-ambient" aria-hidden="true"></div>
<div class="csg-target" aria-hidden="true"></div>
<div class="csg-scan-window" aria-hidden="true">
<div class="csg-sweep">
<div class="csg-scan-line"></div>
</div>
</div>
<div class="csg-corner-layer" aria-hidden="true">
<span class="csg-corner csg-corner-tl"></span>
<span class="csg-corner csg-corner-tr"></span>
<span class="csg-corner csg-corner-br"></span>
<span class="csg-corner csg-corner-bl"></span>
</div>
<div class="csg-confirmation">
<span class="csg-pulse" aria-hidden="true"></span>
<span class="csg-check" aria-hidden="true"></span>
<span class="csg-label"></span>
</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");
// Literal, not read from the DOM. Mounted flattening strips the
// root's data-composition-id before timeline registration.
var compositionId = "camera-scan-gate";
var stage = root.querySelector(".csg-stage");
var cornerLayer = root.querySelector(".csg-corner-layer");
var sweep = root.querySelector(".csg-sweep");
var target = root.querySelector(".csg-target");
var ambient = root.querySelector(".csg-ambient");
var pulse = root.querySelector(".csg-pulse");
var check = root.querySelector(".csg-check");
var label = root.querySelector(".csg-label");
// EDIT ZONE: declared defaults and per-instance overrides have one
// owner after mount, window.__hyperframes.getVariables().
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
var scanColor =
vars.scanColor == null || String(vars.scanColor).trim() === ""
? "var(--brand)"
: String(vars.scanColor);
var targetLabel = vars.targetLabel == null ? "" : String(vars.targetLabel);
var rawSweepSpeed = Number(vars.sweepSpeed);
// INVARIANT: sweep speed is finite and clamped to the declared
// 0.8 to 1.6 range. It never changes IN, HOLD, OUT, or sync points.
var sweepSpeed = Number.isFinite(rawSweepSpeed)
? Math.max(0.8, Math.min(1.6, rawSweepSpeed))
: 1;
root.style.setProperty("--csg-scan-color", scanColor);
label.textContent = targetLabel;
var beatValue = parseFloat(getComputedStyle(root).getPropertyValue("--dur-beat"));
var beat = Number.isFinite(beatValue) && beatValue > 0 ? beatValue : 0.5;
var AMBIENT_HALF = beat * 1.5;
// RETIME RANGE: IN_BASE and OUT_BASE own the interaction envelope.
// The only elastic phase is HOLD. Short durations scale IN and OUT
// together with one factor, never gsap.timeScale().
var IN_BASE = 1.05;
var OUT_BASE = 0.5;
var STAGE_IN_BASE = 0.28;
var SWEEP_DURATION_BASE = 0.4;
var SWEEP_LANDS_BASE = 0.5;
var LOCK_AT_BASE = 0.68;
var LOCK_DURATION_BASE = 0.22;
var CONFIRM_DURATION_BASE = 0.2;
var PULSE_HALF_BASE = 0.18;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4"));
var totalBase = IN_BASE + OUT_BASE;
var scale = duration < totalBase ? duration / totalBase : 1;
var IN = IN_BASE * scale;
var OUT = OUT_BASE * scale;
var STAGE_IN = STAGE_IN_BASE * scale;
var SWEEP_LANDS = SWEEP_LANDS_BASE * scale;
var SWEEP_DURATION = (SWEEP_DURATION_BASE / sweepSpeed) * scale;
var SWEEP_START = Math.max(0, SWEEP_LANDS - SWEEP_DURATION);
var LOCK_AT = LOCK_AT_BASE * scale;
var LOCK_DURATION = LOCK_DURATION_BASE * scale;
var CONFIRM_DURATION = CONFIRM_DURATION_BASE * scale;
var PULSE_HALF = PULSE_HALF_BASE * scale;
var HOLD = Math.max(0, duration - (IN + OUT));
var HOLD_START = IN;
var OUT_START = IN + HOLD;
function fireSfx(id, t) {
root.dispatchEvent(
new CustomEvent("hf:sfx", { detail: { id: id, t: t }, bubbles: true }),
);
}
// Explicit both-endpoints state before timeline construction keeps
// direct seek to t=0 correct without playing through prior frames.
gsap.set(stage, { opacity: 0, scale: 0.94 });
gsap.set(cornerLayer, { scale: 1 });
gsap.set(sweep, { opacity: 1, yPercent: 0 });
gsap.set(target, { opacity: 0, scale: 0.96 });
gsap.set(ambient, { opacity: 0, scale: 1 });
gsap.set(pulse, { opacity: 0, scale: 0.9 });
gsap.set(check, { opacity: 0, scale: 0.94 });
gsap.set(label, { opacity: 0, y: "1.2cqh", scale: 0.96 });
var tl = gsap.timeline({ paused: true });
// IN: settle, scan, then lock. The sweep uses --ease-standard's
// GSAP equivalent and lands at a fixed offset inside IN.
tl.to(stage, { opacity: 1, scale: 1, duration: STAGE_IN, ease: "power2.out" }, 0);
tl.to(
sweep,
{ yPercent: 100, duration: SWEEP_DURATION, ease: "power2.out" },
SWEEP_START,
);
tl.set(sweep, { opacity: 0 }, SWEEP_LANDS);
// recognition-lock is the single causal gate. Corner tightening is
// the one moderate --ease-overshoot motion in this primitive.
tl.to(
cornerLayer,
{ scale: 0.6, duration: LOCK_DURATION, ease: "back.out(1.7)" },
LOCK_AT,
);
tl.to(
target,
{ opacity: 1, scale: 1, duration: CONFIRM_DURATION, ease: "power2.out" },
LOCK_AT,
);
tl.to(
check,
{ opacity: 1, scale: 1, duration: CONFIRM_DURATION, ease: "power2.out" },
LOCK_AT,
);
tl.to(
label,
{ opacity: 1, y: 0, scale: 1, duration: CONFIRM_DURATION, ease: "power2.out" },
LOCK_AT,
);
tl.to(
pulse,
{
opacity: 0.9,
scale: 1.25,
duration: PULSE_HALF,
ease: "power2.out",
yoyo: true,
repeat: 1,
},
LOCK_AT,
);
// Side-effect invariant: this timeline callback is the only actor
// that emits lock-chime, once at the recognition-lock sync point.
tl.call(
function () {
fireSfx("lock-chime", LOCK_AT);
},
[],
LOCK_AT,
);
// HOLD: a separate layer breathes with a finite repeat count, so
// the resolved gate stays alive without competing with lock tweens.
if (HOLD > AMBIENT_HALF) {
var ambientRepeat = Math.max(0, Math.floor(HOLD / AMBIENT_HALF) - 1);
tl.to(
ambient,
{
opacity: 0.3,
scale: 1.015,
duration: AMBIENT_HALF,
ease: "sine.inOut",
yoyo: true,
repeat: ambientRepeat,
},
HOLD_START,
);
}
// OUT: asymmetric release. HOLD alone absorbs duration changes.
tl.to(stage, { opacity: 0, scale: 0.98, duration: OUT, ease: "power2.in" }, OUT_START);
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines[compositionId] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</VariablesExplorer>
## Install
<InstallCommand command="npx hyperframes add camera-scan-gate" item="camera-scan-gate" />
That writes one file: `compositions/components/camera-scan-gate.html`.
## Paste it into your composition
Open `compositions/components/camera-scan-gate.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 |
| --- | --- | --- | --- |
| `scanColor` | `var(--brand)` | string | Any CSS color value used by the scan line and recognition glow. |
| `targetLabel` | `Verified` | string | Confirmation label revealed at recognition lock. Blank hides the line. |
| `sweepSpeed` | `1` | 0.8x to 1.6x, step 0.1x | Speed multiplier for the scan sweep phase only. |
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="camera-scan-gate"
data-composition-src="compositions/components/camera-scan-gate.html"
data-variable-values='{"scanColor":"var(--brand)","targetLabel":"Verified","sweepSpeed":1}'
></div>
```
## Source
<Accordion title={`camera-scan-gate.html`}>
```html
<!doctype html>
<!--
camera-scan-gate -- HyperFrames video primitive (ui-props / interaction / demonstrate)
Concept: a camera viewfinder scans once, tightens its four L-shaped corner
brackets onto a detected target, then confirms recognition with a pulse,
check flash, and target label. One mechanic, one job: demonstrate the causal
scan -> lock -> confirmation gate that unlocks a product's next beat.
Compiled-from evidence: SIM fixture; MOBILE mobile-inventory (scan-to-onboard
and scan-to-pay moments in the video-primitives candidates card).
Use when: a mobile product scene needs a camera, QR, identity, or payment
recognition moment whose successful lock causes the following action. Skip
it for passive camera decoration or a generic loading state.
Variables (declared in data-composition-variables below):
- scanColor (string, default "var(--brand)"): any CSS color value used by
the scan line, lock brackets, and confirmation glow.
- targetLabel (string, default "Verified"): label revealed at lock. Empty
string hides the label line entirely.
- sweepSpeed (number, default 1, range 0.8 to 1.6): scan sweep speed only.
It changes the sweep start while its landing sync point stays fixed.
Envelope (fixed IN/OUT, elastic HOLD only, never gsap.timeScale()):
IN_BASE = 1.05s stage settles, sweep lands, then recognition locks
HOLD = elastic = max(0, D - (IN_BASE + OUT_BASE)); a faint finite
frame glow breathes, or remains still when HOLD == 0
OUT_BASE = 0.50s resolved gate releases with a short fade
If D < IN_BASE + OUT_BASE, IN and OUT scale down together so IN + OUT == D
and HOLD == 0.
Sync points (fixed offsets into IN, never inside elastic HOLD):
- scan-landed: 0.50s into unscaled IN, the --ease-standard sweep completes
- recognition-lock: 0.68s into unscaled IN, brackets tighten with
--ease-overshoot while confirmation and the target label fire
Both offsets scale proportionally only when the full envelope compresses.
Sound cue: a soft recognition chime fires at recognition-lock. The primitive
never plays audio itself. It dispatches an `hf:sfx` CustomEvent
({ id: "lock-chime", t: LOCK_AT }) for the host mix stage to route.
Mount contract: this file is a MOUNTABLE SUB-COMPOSITION, not a standalone
composition. A host loads it via data-composition-src; the runtime clones
only <template> contents, so all live style, markup, and script stays inside
the template. The root has no data-width/data-height and fills the host box
with position:absolute, inset:0, and container-type:size. It is styled by
#root because mounted CSS scoping would stop a root-class selector from
matching the root itself. The hardcoded "camera-scan-gate" composition id
is required because the mounted flattening step strips data-composition-id
before this script registers its timeline. Variables are read through
window.__hyperframes.getVariables(), which owns declared defaults merged
with per-instance host overrides after mounting.
-->
<html
lang="en"
data-composition-variables='[
{ "id": "scanColor", "type": "string", "role": "style", "label": "Scan color", "description": "Any CSS color value used by the scan line and recognition glow.", "default": "var(--brand)" },
{ "id": "targetLabel", "type": "string", "role": "content", "label": "Target label", "description": "Confirmation label revealed at recognition lock. Blank hides the line.", "default": "Verified" },
{ "id": "sweepSpeed", "type": "number", "role": "timing", "label": "Sweep speed", "description": "Speed multiplier for the scan sweep phase only.", "default": 1, "min": 0.8, "max": 1.6, "step": 0.1, "unit": "x" }
]'
>
<head>
<meta charset="UTF-8" />
<title>Camera Scan Gate</title>
<!-- Metadata only. The loader reads variable declarations from this html
element, while the mount runtime discards everything outside the
template. -->
</head>
<body>
<template>
<div
id="root"
data-composition-id="camera-scan-gate"
data-start="0"
data-duration="4"
data-fps="30"
>
<style>
*,
*::before,
*::after {
box-sizing: border-box;
}
/* INVARIANT: the host owns dimensions. #root fills that box and
establishes the cqw/cqh basis for every visible measurement. */
#root {
position: absolute;
inset: 0;
container-type: size;
isolation: isolate;
overflow: hidden;
color: var(--fg, #f8fafc);
font-family: var(--font-body, Inter, system-ui, sans-serif);
}
.csg-clip {
position: relative;
width: 100%;
height: 100%;
display: grid;
place-items: center;
overflow: hidden;
background: var(--bg, #0b1120);
}
.csg-stage {
position: relative;
width: min(64cqw, 76cqh);
aspect-ratio: 1;
opacity: 0;
}
/* EDIT ZONE: the outer viewfinder is a square so one centered scale
operation tightens all four brackets onto the target equally. */
.csg-frame,
.csg-corner-layer,
.csg-scan-window {
position: absolute;
inset: 0;
}
.csg-frame {
border: 0.16cqw solid color-mix(in srgb, var(--border, #334155) 74%, transparent);
border-radius: var(--space-2, 2.4cqw);
background: color-mix(in srgb, var(--surface, #1e293b) 34%, transparent);
box-shadow: inset 0 0 5cqw color-mix(in srgb, var(--bg, #0b1120) 60%, transparent);
}
.csg-grid {
position: absolute;
inset: 0;
border-radius: inherit;
background-image:
linear-gradient(
to right,
transparent 33%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 33% 33.25%,
transparent 33.25% 66.5%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 66.5% 66.75%,
transparent 66.75%
),
linear-gradient(
to bottom,
transparent 33%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 33% 33.25%,
transparent 33.25% 66.5%,
color-mix(in srgb, var(--border, #334155) 32%, transparent) 66.5% 66.75%,
transparent 66.75%
);
opacity: 0.55;
}
.csg-ambient {
position: absolute;
inset: -4%;
border: 0.45cqw solid
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 48%, transparent);
border-radius: var(--space-3, 3.2cqw);
box-shadow: 0 0 4.5cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 38%, transparent);
opacity: 0;
}
.csg-corner-layer {
transform-origin: center;
z-index: 3;
}
.csg-corner {
position: absolute;
width: 18%;
height: 18%;
border-color: var(--csg-scan-color, var(--brand, #22c55e));
border-style: solid;
filter: drop-shadow(
0 0 0.9cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 56%, transparent)
);
}
.csg-corner-tl {
top: 0;
left: 0;
border-width: 0.65cqw 0 0 0.65cqw;
border-radius: var(--space-2, 2.4cqw) 0 0;
}
.csg-corner-tr {
top: 0;
right: 0;
border-width: 0.65cqw 0.65cqw 0 0;
border-radius: 0 var(--space-2, 2.4cqw) 0 0;
}
.csg-corner-br {
right: 0;
bottom: 0;
border-width: 0 0.65cqw 0.65cqw 0;
border-radius: 0 0 var(--space-2, 2.4cqw);
}
.csg-corner-bl {
bottom: 0;
left: 0;
border-width: 0 0 0.65cqw 0.65cqw;
border-radius: 0 0 0 var(--space-2, 2.4cqw);
}
.csg-scan-window {
z-index: 2;
inset: 3.5%;
overflow: hidden;
}
.csg-sweep {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
.csg-scan-line {
position: absolute;
inset: 0 0 auto;
width: 100%;
height: 0.38cqh;
border-radius: 999cqw;
background: var(--csg-scan-color, var(--brand, #22c55e));
box-shadow:
0 0 1.2cqw var(--csg-scan-color, var(--brand, #22c55e)),
0 1.8cqh 3.6cqh
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 42%, transparent);
}
.csg-target {
position: absolute;
z-index: 1;
width: 60%;
height: 60%;
top: 20%;
left: 20%;
border: 0.2cqw solid
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 65%, transparent);
border-radius: var(--space-2, 2.4cqw);
background: color-mix(
in srgb,
var(--csg-scan-color, var(--brand, #22c55e)) 7%,
transparent
);
opacity: 0;
}
.csg-confirmation {
position: absolute;
z-index: 4;
inset: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: var(--space-2, 2.2cqh);
}
.csg-pulse {
position: absolute;
width: 30%;
aspect-ratio: 1;
border: 0.42cqw solid var(--csg-scan-color, var(--brand, #22c55e));
border-radius: 50%;
box-shadow: 0 0 4.5cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 58%, transparent);
opacity: 0;
}
.csg-check {
display: block;
width: 8.5%;
height: 15%;
margin-top: -5%;
border-right: 0.8cqw solid var(--csg-scan-color, var(--brand, #22c55e));
border-bottom: 0.8cqw solid var(--csg-scan-color, var(--brand, #22c55e));
filter: drop-shadow(
0 0 1.1cqw
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 65%, transparent)
);
opacity: 0;
transform: rotate(45deg);
}
.csg-label {
min-width: 34%;
padding: var(--space-1, 1cqh) var(--space-3, 3cqw);
border: 0.14cqw solid
color-mix(in srgb, var(--csg-scan-color, var(--brand, #22c55e)) 48%, transparent);
border-radius: 999cqw;
background: color-mix(in srgb, var(--surface, #1e293b) 88%, transparent);
color: var(--fg, #f8fafc);
font-family: var(--font-display, Inter, system-ui, sans-serif);
font-size: clamp(2cqh, 2.8cqw, 3.3cqh);
font-weight: 760;
letter-spacing: 0.035em;
line-height: 1.1;
text-align: center;
opacity: 0;
}
.csg-label:empty {
display: none;
}
</style>
<div
id="camera-scan-gate-clip"
class="csg-clip clip"
data-start="0"
data-duration="4"
data-track-index="0"
>
<div class="csg-stage" role="img" aria-label="Camera recognition scanner">
<div class="csg-frame">
<div class="csg-grid" aria-hidden="true"></div>
</div>
<div class="csg-ambient" aria-hidden="true"></div>
<div class="csg-target" aria-hidden="true"></div>
<div class="csg-scan-window" aria-hidden="true">
<div class="csg-sweep">
<div class="csg-scan-line"></div>
</div>
</div>
<div class="csg-corner-layer" aria-hidden="true">
<span class="csg-corner csg-corner-tl"></span>
<span class="csg-corner csg-corner-tr"></span>
<span class="csg-corner csg-corner-br"></span>
<span class="csg-corner csg-corner-bl"></span>
</div>
<div class="csg-confirmation">
<span class="csg-pulse" aria-hidden="true"></span>
<span class="csg-check" aria-hidden="true"></span>
<span class="csg-label"></span>
</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");
// Literal, not read from the DOM. Mounted flattening strips the
// root's data-composition-id before timeline registration.
var compositionId = "camera-scan-gate";
var stage = root.querySelector(".csg-stage");
var cornerLayer = root.querySelector(".csg-corner-layer");
var sweep = root.querySelector(".csg-sweep");
var target = root.querySelector(".csg-target");
var ambient = root.querySelector(".csg-ambient");
var pulse = root.querySelector(".csg-pulse");
var check = root.querySelector(".csg-check");
var label = root.querySelector(".csg-label");
// EDIT ZONE: declared defaults and per-instance overrides have one
// owner after mount, window.__hyperframes.getVariables().
var vars =
window.__hyperframes && window.__hyperframes.getVariables
? window.__hyperframes.getVariables()
: {};
var scanColor =
vars.scanColor == null || String(vars.scanColor).trim() === ""
? "var(--brand)"
: String(vars.scanColor);
var targetLabel = vars.targetLabel == null ? "" : String(vars.targetLabel);
var rawSweepSpeed = Number(vars.sweepSpeed);
// INVARIANT: sweep speed is finite and clamped to the declared
// 0.8 to 1.6 range. It never changes IN, HOLD, OUT, or sync points.
var sweepSpeed = Number.isFinite(rawSweepSpeed)
? Math.max(0.8, Math.min(1.6, rawSweepSpeed))
: 1;
root.style.setProperty("--csg-scan-color", scanColor);
label.textContent = targetLabel;
var beatValue = parseFloat(getComputedStyle(root).getPropertyValue("--dur-beat"));
var beat = Number.isFinite(beatValue) && beatValue > 0 ? beatValue : 0.5;
var AMBIENT_HALF = beat * 1.5;
// RETIME RANGE: IN_BASE and OUT_BASE own the interaction envelope.
// The only elastic phase is HOLD. Short durations scale IN and OUT
// together with one factor, never gsap.timeScale().
var IN_BASE = 1.05;
var OUT_BASE = 0.5;
var STAGE_IN_BASE = 0.28;
var SWEEP_DURATION_BASE = 0.4;
var SWEEP_LANDS_BASE = 0.5;
var LOCK_AT_BASE = 0.68;
var LOCK_DURATION_BASE = 0.22;
var CONFIRM_DURATION_BASE = 0.2;
var PULSE_HALF_BASE = 0.18;
var duration = Math.max(0.001, parseFloat(root.dataset.duration || "4"));
var totalBase = IN_BASE + OUT_BASE;
var scale = duration < totalBase ? duration / totalBase : 1;
var IN = IN_BASE * scale;
var OUT = OUT_BASE * scale;
var STAGE_IN = STAGE_IN_BASE * scale;
var SWEEP_LANDS = SWEEP_LANDS_BASE * scale;
var SWEEP_DURATION = (SWEEP_DURATION_BASE / sweepSpeed) * scale;
var SWEEP_START = Math.max(0, SWEEP_LANDS - SWEEP_DURATION);
var LOCK_AT = LOCK_AT_BASE * scale;
var LOCK_DURATION = LOCK_DURATION_BASE * scale;
var CONFIRM_DURATION = CONFIRM_DURATION_BASE * scale;
var PULSE_HALF = PULSE_HALF_BASE * scale;
var HOLD = Math.max(0, duration - (IN + OUT));
var HOLD_START = IN;
var OUT_START = IN + HOLD;
function fireSfx(id, t) {
root.dispatchEvent(
new CustomEvent("hf:sfx", { detail: { id: id, t: t }, bubbles: true }),
);
}
// Explicit both-endpoints state before timeline construction keeps
// direct seek to t=0 correct without playing through prior frames.
gsap.set(stage, { opacity: 0, scale: 0.94 });
gsap.set(cornerLayer, { scale: 1 });
gsap.set(sweep, { opacity: 1, yPercent: 0 });
gsap.set(target, { opacity: 0, scale: 0.96 });
gsap.set(ambient, { opacity: 0, scale: 1 });
gsap.set(pulse, { opacity: 0, scale: 0.9 });
gsap.set(check, { opacity: 0, scale: 0.94 });
gsap.set(label, { opacity: 0, y: "1.2cqh", scale: 0.96 });
var tl = gsap.timeline({ paused: true });
// IN: settle, scan, then lock. The sweep uses --ease-standard's
// GSAP equivalent and lands at a fixed offset inside IN.
tl.to(stage, { opacity: 1, scale: 1, duration: STAGE_IN, ease: "power2.out" }, 0);
tl.to(
sweep,
{ yPercent: 100, duration: SWEEP_DURATION, ease: "power2.out" },
SWEEP_START,
);
tl.set(sweep, { opacity: 0 }, SWEEP_LANDS);
// recognition-lock is the single causal gate. Corner tightening is
// the one moderate --ease-overshoot motion in this primitive.
tl.to(
cornerLayer,
{ scale: 0.6, duration: LOCK_DURATION, ease: "back.out(1.7)" },
LOCK_AT,
);
tl.to(
target,
{ opacity: 1, scale: 1, duration: CONFIRM_DURATION, ease: "power2.out" },
LOCK_AT,
);
tl.to(
check,
{ opacity: 1, scale: 1, duration: CONFIRM_DURATION, ease: "power2.out" },
LOCK_AT,
);
tl.to(
label,
{ opacity: 1, y: 0, scale: 1, duration: CONFIRM_DURATION, ease: "power2.out" },
LOCK_AT,
);
tl.to(
pulse,
{
opacity: 0.9,
scale: 1.25,
duration: PULSE_HALF,
ease: "power2.out",
yoyo: true,
repeat: 1,
},
LOCK_AT,
);
// Side-effect invariant: this timeline callback is the only actor
// that emits lock-chime, once at the recognition-lock sync point.
tl.call(
function () {
fireSfx("lock-chime", LOCK_AT);
},
[],
LOCK_AT,
);
// HOLD: a separate layer breathes with a finite repeat count, so
// the resolved gate stays alive without competing with lock tweens.
if (HOLD > AMBIENT_HALF) {
var ambientRepeat = Math.max(0, Math.floor(HOLD / AMBIENT_HALF) - 1);
tl.to(
ambient,
{
opacity: 0.3,
scale: 1.015,
duration: AMBIENT_HALF,
ease: "sine.inOut",
yoyo: true,
repeat: ambientRepeat,
},
HOLD_START,
);
}
// OUT: asymmetric release. HOLD alone absorbs duration changes.
tl.to(stage, { opacity: 0, scale: 0.98, duration: OUT, ease: "power2.in" }, OUT_START);
tl.seek(0);
window.__timelines = window.__timelines || {};
window.__timelines[compositionId] = tl;
})();
</script>
</div>
</template>
</body>
</html>
```
</Accordion>
{/* hf:generated-footer */}
Tagged `prop` `ui-props` `camera` `qr` `scan` `recognition` `interaction` `demonstrate`.
## Related topics
- [Browse the complete Catalog](/catalog)
- [Add assets and Catalog items in Studio](/studio/assets-and-blocks)
- [Build a richer composition](/go-further)