Controladores y líneas de tiempo
Reproducir, pausar, invertir, posicionar, terminar y cancelar; valores de movimiento; WAAPI; líneas de tiempo; efectos dirigidos por scroll.
Experimental y no disponible en npm
Todo lo que se ejecuta devuelve un control con las mismas reglas.
El control
| Método | Efecto |
|---|---|
play() | Avanza en la dirección actual; desde un estado final inicia una ejecución nueva |
pause() | Conserva el valor actual y quita la tarea por fotograma |
reverse() | Invierte la dirección; desde un estado final inicia una ejecución nueva |
seek(p) | Dibuja exactamente el progreso 0–1 (tweens, WAAPI, líneas de tiempo y efectos de progreso; no resortes) |
finish() | Salta al final de la dirección actual |
cancel() | Se detiene donde está |
state es idle, running, paused, completed, cancelled, interrupted o failed. finished es
la promesa de la ejecución actual:
- se resuelve con
status"completed","cancelled"o"interrupted"; los resultados normales nunca la rechazan, así que puedes ignorarla sin riesgo; - se rechaza solo ante un error real.
Animar un valor
import { animateValue, bindChannel, motionValue } from "@neshel-ui/animations/core";
export async function openDrawer(panel: HTMLElement) {
const x = motionValue(-320);
const release = bindChannel(
x,
panel,
{ channel: "transform", layer: (value) => ({ translateX: value }) },
{ effectId: "app/drawer" },
);
const result = await animateValue(x, 0, { type: "spring", spring: "snappy" }).finished;
if (result.status === "completed") release();
}Animar un valor otra vez interrumpe la ejecución anterior desde donde está; los resortes conservan su
velocidad. animateElement ejecuta una animación WAAPI sobre un canal exclusivo como filter o
clip-path; transform y opacity usan valores de movimiento para seguir componiéndose.
Líneas de tiempo
import { createTimeline } from "@neshel-ui/animations/cinematic";
import { fadeUp } from "@neshel-ui/animations/entrance";
export function intro(title: HTMLElement, card: HTMLElement) {
const timeline = createTimeline();
timeline.add({ target: title, effect: fadeUp });
timeline.label("cards", "-=200");
timeline.add({ target: card, from: { x: -80, opacity: 0 }, to: { x: 0, opacity: 1 } }, "cards");
timeline.call(() => console.log("cards in view"), "cards");
timeline.play();
return () => timeline.destroy();
}Posiciones: un número de milisegundos, "etiqueta" o "etiqueta+=100", "<" (inicio de la pista
anterior), ">" (su final, por defecto) y "+=100" o "-=100" desde el final actual.
Pistas: una pose (from/to con x, y, scale, rotate, opacity, blur), un valor de
movimiento, un efecto de entrada o una línea de tiempo anidada. Una pista de entrada va ligada por
defecto — sigue a la línea de tiempo exactamente — o disparada con su propio reloj
(mode: "trigger").
repeat es 0 por defecto e Infinity solo de forma explícita. Con la página oculta el reloj se pausa, o
termina con whenHidden: "finish". Con movimiento reducido la línea de tiempo termina de inmediato.
En React, useTimeline la crea y la destruye con el componente:
C01.
Dirigir un efecto con un progreso
Los efectos de texto, SVG, medios, 3D y GPU aceptan cualquier fuente de 0 a 1 en lugar de su reloj:
"use client";
import "@neshel-ui/animations/text.css";
import { useScrollProgress } from "@neshel-ui/animations/scroll";
import { LineReveal } from "@neshel-ui/animations/text";
import { useRef } from "react";
export function ScrollTitle({ children }: { children: string }) {
const ref = useRef<HTMLDivElement>(null);
const progress = useScrollProgress(ref);
return (
<div ref={ref}>
<LineReveal source={progress} mode="scrub">
{children}
</LineReveal>
</div>
);
}O secuéncialo dentro de una línea de tiempo con su track():
import { createTimeline } from "@neshel-ui/animations/cinematic";
import { createPathDraw } from "@neshel-ui/animations/svg";
import { createTypewriter } from "@neshel-ui/animations/text";
export function sequence(path: SVGPathElement, line: HTMLElement) {
const draw = createPathDraw(path, { trigger: "manual" });
const type = createTypewriter(line, { trigger: "manual" });
const timeline = createTimeline();
timeline.add(draw.track({ duration: 900 }));
timeline.add(type.track({ duration: 1200 }));
timeline.play();
return () => {
timeline.destroy();
draw.destroy();
type.destroy();
};
}