Cine y escenas
Los 10 efectos C01–C10: propósito, API, opciones, ejemplos, movimiento reducido y coste.
Experimental y no disponible en npm
Los efectos cinematográficos comparten una idea: una línea de tiempo es una función pura del tiempo que se dibuja a través del motion host de cada elemento, así que se puede posicionar, arrastrar e invertir, y se compone con los demás efectos. El HTML del servidor es el contenido visible; cubiertas, lentes y bandas son capas del paquete (aria-hidden, inertes) que solo aparecen con JavaScript. Cada efecto ofrece track() para secuenciarlo en una línea de tiempo.
C01 · Línea de tiempo
useTimeline crea una línea de tiempo para un componente y la destruye con él; createTimeline es el motor. add coloca pistas una tras otra, en una etiqueta o con desfases como "-=300"; play, pause, reverse y seek(0–1) la controlan.
- Importación
@neshel-ui/animations/cinematic- API
createTimeline, useTimeline- Hoja de estilos
- no hace falta
- Movimiento reducido
instant— el estado final aparece de inmediato- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import { useTimeline } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function C01Example() {
const first = useRef<HTMLDivElement>(null);
const second = useRef<HTMLDivElement>(null);
const timeline = useTimeline((tl) => {
if (!first.current || !second.current) return;
tl.add({ target: first.current, to: { x: 200 }, duration: 700 });
tl.label("overlap", "-=300");
tl.add({ target: second.current, to: { x: 200, rotate: 180 }, duration: 700 }, "overlap");
}, []);
return (
<div className="grid gap-3">
<div ref={first} className="h-8 w-12 rounded bg-neshel-primary" />
<div ref={second} className="h-8 w-12 rounded bg-neshel-accent" />
<div className="flex flex-wrap gap-2">
<Button onClick={() => timeline.play()}>Play</Button>
<Button variant="outline" onClick={() => timeline.pause()}>
Pause
</Button>
<Button variant="outline" onClick={() => timeline.reverse()}>
Reverse
</Button>
<Button variant="outline" onClick={() => timeline.seek(0.5)}>
Seek 50 %
</Button>
</div>
</div>
);
}Opciones: TimelineOptions
TimelineOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| conflicts | ConflictPolicy | — | Aviso de conflictos en canales exclusivos (desenfoque de poses, pistas de efectos). |
| onComplete | (result: MotionResult) => void | — | Una vez por ejecución completada. |
| onRepeat | (iteration: number) => void | — | — |
| onStart | () => void | — | — |
| onUpdate | (time: number, progress: number) => void | — | — |
| reducedMotion | ReducedMotion | — | — |
| repeat | number | — | Iteraciones extra: 0 (por defecto) … 1000, o Infinity (solo explícito). |
| timeScale | number | 1 | 0.1–10 (por defecto 1). |
| whenHidden | "pause" | "finish" | — | Con la página oculta: detener el reloj (por defecto) o terminar. |
| yoyo | boolean | false | Alterna la dirección en cada repetición (por defecto false). |
C02 · Capítulos de escena
<SceneChapters> divide un progreso en <Chapter> según su weight; cada <SceneSegment> anima una parte de su capítulo (span). Dale el source de un <ScrollScene> o un progress controlado; onChapterChange informa el activo.
- Importación
@neshel-ui/animations/cinematic- API
SceneChapters, Chapter, SceneSegment, createSceneChapters- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
static— la decoración o el contenido permanece quieto- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { Chapter, SceneChapters, SceneSegment } from "@neshel-ui/animations/cinematic";
import { fadeUp } from "@neshel-ui/animations/entrance";
import { useState } from "react";
export default function C02Example() {
const [progress, setProgress] = useState(0.2);
return (
<div className="grid gap-4">
<label className="grid gap-1">
Progress (a ScrollScene provides it on a page)
<input
type="range"
min={0}
max={1}
step={0.01}
value={progress}
onChange={(event) => setProgress(Number(event.currentTarget.value))}
/>
</label>
<SceneChapters progress={progress} className="grid gap-3">
<Chapter id="arrival">
<SceneSegment
effect={fadeUp}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
Arrival
</SceneSegment>
</Chapter>
<Chapter id="journey" weight={2}>
<SceneSegment
from={{ x: -120, opacity: 0 }}
span={[0, 0.6]}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
The journey lasts twice as long
</SceneSegment>
</Chapter>
</SceneChapters>
</div>
);
}Opciones: SceneChaptersOptions
SceneChaptersOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| chapters(obligatoria) | readonly ChapterInput[] | — | — |
| onChapterChange | (id: string, index: number) => void | — | — |
| reducedMotion | ReducedMotion | — | — |
| unit | number | — | Duración del reloj sin fuente, ms por unidad de peso (100–20000, por defecto 1500). |
C03 · Cámara
<CameraStage> se desplaza y amplía sobre un lienzo grande. useCamera() la mueve: camera.to({ focus: elemento }) o { x, y, zoom }. El foco de teclado dentro del lienzo arrastra la cámara, y sin JavaScript es una región con scroll.
- Importación
@neshel-ui/animations/cinematic- API
CameraStage, useCamera, createCamera- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
static— la decoración o el contenido permanece quieto- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { CameraStage, useCamera } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useRef } from "react";
export default function C03Example() {
const camera = useCamera();
const places = useRef<Array<HTMLButtonElement | null>>([]);
return (
<div className="grid gap-3">
<CameraStage
label="Map"
camera={camera}
minZoom={0.25}
className="h-64 rounded-xl border border-neshel-border"
>
<div className="grid w-[1000px] grid-cols-3 gap-10 p-10">
{["North", "East", "South", "West", "Harbour", "Summit"].map((name, index) => (
<button
key={name}
type="button"
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground h-40"
ref={(node) => {
places.current[index] = node;
}}
>
{name}
</button>
))}
</div>
</CameraStage>
<div className="flex gap-2">
<Button
variant="outline"
onClick={() => {
const place = places.current[4];
if (place) void camera.to({ focus: place });
}}
>
Go to the harbour
</Button>
<Button variant="outline" onClick={() => void camera.to({ x: 500, y: 220, zoom: 0.3 })}>
Overview
</Button>
</div>
</div>
);
}Opciones: CameraOptions
CameraOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| bounds | "contain" | "none" | — | "contain" mantiene el lienzo cubriendo el escenario (por defecto); "none" permite cualquier pose. |
| followFocus | boolean | true | Se desplaza hasta los elementos que reciben foco de teclado dentro del lienzo (por defecto true). |
| initial | Partial<CameraPose> | — | Pose inicial (por defecto: centro del lienzo con zoom 1). |
| maxZoom | number | 4 | 1–10 (por defecto 4). |
| minZoom | number | 0.5 | 0.1–1 (por defecto 0.5). |
| onChange | (pose: CameraPose) => void | — | — |
| padding | number | — | Espacio alrededor de un elemento enfocado (0–400, por defecto 24). |
| reducedMotion | ReducedMotion | — | — |
C04 · Revelado dividido
<SplitReveal> cubre su contenido con dos mitades que se separan en direction ("x" o "y"). open lo controla; sin open se revela una vez al montarse en el cliente.
- Importación
@neshel-ui/animations/cinematic- API
SplitReveal, createCover- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
instant— el estado final aparece de inmediato- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { SplitReveal } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function C04Example() {
const [open, setOpen] = useState(true);
return (
<div className="grid justify-items-start gap-3">
<SplitReveal
open={open}
direction="x"
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
The cover opens in two halves
</SplitReveal>
<Button variant="outline" onClick={() => setOpen(!open)}>
{open ? "Cover" : "Open"}
</Button>
</div>
);
}Opciones: CoverOptions
CoverOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| covered | boolean | true | Empieza cubierto (por defecto true) o abierto. |
| pattern | CoverPattern | "split-x" | Por defecto "split-x". |
| reducedMotion | ReducedMotion | — | — |
| slats | number | — | Lamas de la persiana (2–12, por defecto 6). |
C05 · Telón y persiana
<CurtainReveal> se abre desde el centro con pattern="curtain" o en lamas (slats) con pattern="shutter". El contenido de debajo no recibe escrituras y sigue en el árbol de accesibilidad.
- Importación
@neshel-ui/animations/cinematic- API
CurtainReveal, createCover- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
instant— el estado final aparece de inmediato- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { CurtainReveal } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function C05Example() {
const [open, setOpen] = useState(true);
return (
<div className="grid justify-items-start gap-3">
<CurtainReveal
open={open}
pattern="curtain"
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
Curtain
</CurtainReveal>
<CurtainReveal
open={open}
pattern="shutter"
slats={8}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
Shutter with eight slats
</CurtainReveal>
<Button variant="outline" onClick={() => setOpen(!open)}>
{open ? "Close" : "Open"}
</Button>
</div>
);
}Opciones: CoverOptions
CoverOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| covered | boolean | true | Empieza cubierto (por defecto true) o abierto. |
| pattern | CoverPattern | "split-x" | Por defecto "split-x". |
| reducedMotion | ReducedMotion | — | — |
| slats | number | — | Lamas de la persiana (2–12, por defecto 6). |
C06 · Secuencia de títulos
<TitleSequence> ejecuta sus hijos uno tras otro con una entrada (effect) cada interval ms, sobre un background opcional. No divide el texto: cada hijo es una línea.
- Importación
@neshel-ui/animations/cinematic- API
TitleSequence, titleSequence- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
fade— solo opacidad, sin desplazamiento- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Rooted in faith
Built with hope
"use client";
import "@neshel-ui/animations/cinematic.css";
import { TitleSequence } from "@neshel-ui/animations/cinematic";
import { fadeUp } from "@neshel-ui/animations/entrance";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function C06Example() {
const [run, setRun] = useState(0);
return (
<div className="grid justify-items-start gap-3">
<TitleSequence effect={fadeUp} interval={180} replay={run} className="p-4">
<p className="text-2xl font-semibold">Rooted in faith</p>
<p>Built with hope</p>
</TitleSequence>
<Button variant="outline" onClick={() => setRun(run + 1)}>
Replay
</Button>
</div>
);
}Opciones: TitleSequenceOptions
TitleSequenceOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| at | TimelinePosition | — | Dónde empieza la secuencia en la línea de tiempo (por defecto, su final actual). |
| background | Element | null | — | — |
| backgroundDuration | number | — | ms (0–10000, por defecto 1200). |
| backgroundFrom | Pose | { opacity: 0, scale: 1.08 } | Pose inicial del fondo (por defecto { opacity: 0, scale: 1.08 }); termina en la identidad. |
| effect(obligatoria) | PresetInput<any, any> | — | Entrada (definición o preset) ejecutada en cada línea. |
| interval | number | — | ms entre inicios de línea (0–1000, por defecto 120). |
| lines(obligatoria) | readonly Element[] | — | — |
| options | object | — | Opciones combinadas en las del efecto para cada línea. |
| reducedMotion | ReducedMotion | — | — |
C07 · Foco y viñeta
<Spotlight> oscurece el escenario salvo un círculo alrededor de target (radius, padding). El contenido oscurecido sigue siendo interactivo; la lente es decorativa, así que describe el paso con texto.
- Importación
@neshel-ui/animations/cinematic- API
Spotlight, createSpotlight- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
static— la decoración o el contenido permanece quieto- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { Spotlight } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useRef, useState } from "react";
export default function C07Example() {
const steps = useRef<Array<HTMLLIElement | null>>([]);
const [lit, setLit] = useState<number | null>(null);
return (
<div className="grid gap-3">
<Spotlight
target={lit === null ? null : steps.current[lit]}
radius={60}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
<ul className="flex gap-12">
{["Plan", "Build", "Ship"].map((step, index) => (
<li
key={step}
ref={(node) => {
steps.current[index] = node;
}}
>
{step}
</li>
))}
</ul>
</Spotlight>
<div className="flex gap-2">
{[0, 1, 2].map((index) => (
<Button key={index} variant="outline" onClick={() => setLit(index)}>
Light {index + 1}
</Button>
))}
<Button variant="outline" onClick={() => setLit(null)}>
Clear
</Button>
</div>
</div>
);
}Opciones: SpotlightOptions
SpotlightOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| padding | number | — | Espacio extra alrededor de la caja del elemento (0–200, por defecto 16). |
| radius | number | — | Radio por defecto del círculo iluminado (24–800, por defecto 120). |
| reducedMotion | ReducedMotion | — | — |
C08 · Profundidad de campo
<DepthOfField> desenfoca sus hijos según su distancia al índice focus: falloff (4 px por paso) hasta maxBlur (8). Seis capas como máximo; −1 mantiene todo nítido.
- Importación
@neshel-ui/animations/cinematic- API
DepthOfField, createDepthOfField- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
static— la decoración o el contenido permanece quieto- Rendimiento
- Repinta el elemento (color, degradado, recorte, máscara, desenfoque o trazo) mientras se ejecuta; conviene un área pequeña.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { DepthOfField } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function C08Example() {
const [focus, setFocus] = useState(-1);
return (
<div className="grid gap-3">
<DepthOfField focus={focus} className="grid gap-2">
{["Foreground", "Subject", "Background"].map((layer) => (
<div
key={layer}
className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground"
>
{layer}
</div>
))}
</DepthOfField>
<div className="flex flex-wrap gap-2">
{["Foreground", "Subject", "Background"].map((layer, index) => (
<Button key={layer} variant="outline" onClick={() => setFocus(index)}>
{layer}
</Button>
))}
<Button variant="outline" onClick={() => setFocus(-1)}>
All sharp
</Button>
</div>
</div>
);
}Opciones: DepthOfFieldOptions
DepthOfFieldOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| falloff | number | — | Desenfoque por capa de distancia en px (0–12, por defecto 4). |
| focus | number | — | Capa enfocada inicialmente (por defecto ninguna: todo nítido). |
| maxBlur | number | — | Límite de desenfoque en px (0–12, por defecto 8). |
| priority | number | 0 | Prioridad sobre el canal filter (por defecto 0). |
| reducedMotion | ReducedMotion | — | — |
| scale | number | — | Reducción de escala por capa de distancia (0–0.1, por defecto 0.02). |
C09 · Guion gráfico
<Storyboard> es un carrusel de <StoryboardFrame> con controles de rotación, anterior, siguiente y parada, y un label. autoplay es opcional, se pausa con hover, foco, fuera de pantalla y página oculta, y nunca corre con movimiento reducido. Los controles son botones sin estilo; si tu CSS elimina su relleno, dales al menos 24 × 24 px.
- Importación
@neshel-ui/animations/cinematic- API
Storyboard, StoryboardFrame, createStoryboard- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
off— sin movimiento- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { Storyboard, StoryboardFrame } from "@neshel-ui/animations/cinematic";
export default function C09Example() {
return (
<Storyboard
label="A day"
interval={5000}
transition="slide"
// The controls are plain buttons: with a CSS reset, give them a 24 px target size.
className="[&_button]:min-h-6 [&_button]:min-w-6"
>
{["Sunrise", "Noon", "Dusk"].map((moment) => (
<StoryboardFrame key={moment} label={moment}>
<p className="rounded-xl border border-neshel-border bg-neshel-surface p-6 text-neshel-surface-foreground">
{moment}
</p>
</StoryboardFrame>
))}
</Storyboard>
);
}Opciones: StoryboardOptions
StoryboardOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| autoplay | boolean | — | Empieza a rotar automáticamente (por defecto false; nunca con movimiento reducido). |
| duration | number | — | ms de un cambio de fotograma (0–2000, por defecto 450). |
| interval | number | — | ms por fotograma en automático (2000–30000, por defecto 5000). |
| loop | boolean | true | Pasa del último fotograma al primero (por defecto true). |
| onChange | (index: number, cause: "user" | "autoplay") => void | — | — |
| onPlayingChange | (playing: boolean) => void | — | — |
| reducedMotion | ReducedMotion | — | — |
| start | number | 0 | Fotograma inicial (por defecto 0). |
| transition | "fade" | "slide" | "fade" | Tipo de cambio (por defecto "fade"). |
C10 · Bandas de cine
<Letterbox> desliza dos bandas mientras active es verdadero, con ratio 2.39 por defecto. Crea un marco posicionado; el contenido no cambia de tamaño.
- Importación
@neshel-ui/animations/cinematic- API
Letterbox, createLetterbox- Hoja de estilos
@neshel-ui/animations/cinematic.css- Movimiento reducido
instant— el estado final aparece de inmediato- Rendimiento
- Transform y opacity, una escritura por fotograma con el planificador compartido; sin trabajo de layout por fotograma.
Cargando el ejemplo…
"use client";
import "@neshel-ui/animations/cinematic.css";
import { Letterbox } from "@neshel-ui/animations/cinematic";
import { Button } from "@neshel-ui/components";
import { useState } from "react";
export default function C10Example() {
const [active, setActive] = useState(false);
return (
<div className="grid gap-3">
<Letterbox
active={active}
ratio={2.39}
className="grid h-56 max-w-md place-items-center rounded-xl bg-neshel-muted"
>
The scene
</Letterbox>
<Button variant="outline" onClick={() => setActive(!active)} className="justify-self-start">
Cinema bars
</Button>
</div>
);
}Opciones: LetterboxOptions
LetterboxOptions
| Prop | Tipo | Predeterminado | Descripción |
|---|---|---|---|
| reducedMotion | ReducedMotion | — | — |
| shown | boolean | false | Empieza con las bandas visibles (por defecto false). |