import { V as Node, o as Group } from "./nodes.js"; import { Rng, Track } from "@glissade/core"; import { ChannelOverride, Clip } from "@glissade/core/clips"; //#region src/each.d.ts /** An aspect-fraction placement: [fx, fy], each conventionally in [0, 1]. */ type Place = readonly [number, number]; /** * Built-in layouts (a discriminated union — NOT factory fns) plus the escape * hatch `(i, n) => [fx, fy]`. Every built-in is PURE arithmetic in aspect * fractions; mapping to px happens only when `box` is given (see `places`). */ type EachLayout = { kind: 'row'; gap?: number; align?: number; } | { kind: 'column'; gap?: number; align?: number; } | { kind: 'grid'; cols: number; rows?: number; gapX?: number; gapY?: number; order?: 'row' | 'column'; } | { kind: 'ring'; radius?: number; center?: Place; startAngle?: number; sweep?: number; } | ((i: number, n: number) => Place); /** How a `stagger` delay distributes across the clones. */ type EachDistribute = 'delay' | 'from-center' | 'from-edges'; /** Per-index motion: a clip fanned across the clones with stagger + jitter. */ interface EachMotion { /** The motion clip applied to every clone (TYPE: `Clip` from core/clips). */ clip: Clip; /** Wall-clock start second of the first clone. Default 0. */ startSec?: number; /** Per-index delay (seconds) or a function of the index. Default 0. */ stagger?: number | ((i: number) => number); /** * Shape a numeric `stagger` gap into a distribution. `from-center` ramps the * delay outward from the middle clone, `from-edges` inward toward it; `delay` * (the default) is the plain `i * gap` ramp. Ignored when `stagger` is a fn. */ distribute?: EachDistribute; /** Per-index clip overrides, seeded — `(i, rng, n) => overrides`. */ jitter?: (i: number, rng: Rng, n: number) => Record; /** Clip speed (passed straight to `clip.apply`). */ speed?: number; } /** Pixel box for mapping aspect-fraction places to a concrete coordinate frame. */ interface EachBox { w: number; h: number; /** Top-left of the box in scene coords; default [0, 0]. */ origin?: Place; } interface EachOpts { /** Stable id prefix; clones are `${id}/${i}`, the wrapping group is `${id}`. */ id: string; layout: EachLayout; motion?: EachMotion; /** Seed for per-clone RNG; defaults to a stable hash of `id`. */ seed?: number; /** When given, `places` also carries the px-mapped points (see EachResult). */ box?: EachBox; } /** The per-clone authoring context handed to the factory. */ interface EachContext { /** Clone index, 0..n-1. */ i: number; /** Total clone count. */ n: number; /** This clone's id (`${opts.id}/${i}`). */ id: string; /** Aspect-fraction placement [fx, fy] — ALWAYS a fraction (px is separate). */ place: Place; /** Seeded generator for this clone: `random(mix(seed, i))`. */ rng: Rng; /** The resolved base seed (`opts.seed ?? hash(id)`). */ seed: number; } interface EachResult { /** The wrapping group (`id: opts.id`) holding every generated child. */ node: Group; /** The generated children, in index order. */ children: Node[]; /** The compiled motion tracks (empty when no `motion`). */ tracks: Track[]; /** Max child clip end (== startSec when no motion). */ end: number; /** * Per-clone placement. `frac` is the aspect-fraction [fx, fy] every layout * produces; `px` is present only when `opts.box` was given (frac mapped into * the box). Authoring a `box` once here is the single place fraction→px lives. */ places: { frac: Place; px?: Place; }[]; } declare class EachError extends Error { constructor(message: string); } /** * Generate `n` clones from `factory`, lay them out, and (optionally) stagger a * motion clip across them. * * const grid = each(9, (i) => new Rect({ width: 40, height: 40, fill: '#9ef0c0' }), { * id: 'card', * layout: { kind: 'grid', cols: 3 }, * box: { w: 600, h: 360 }, * motion: { clip: popIn(), stagger: 0.08, distribute: 'from-center' }, * }); * // scene children: [grid.node]; timeline tracks: [...grid.tracks] */ declare function each(n: number, factory: (i: number, ctx: EachContext) => Node, opts: EachOpts): EachResult; //#endregion export { EachLayout as a, EachResult as c, EachError as i, Place as l, EachContext as n, EachMotion as o, EachDistribute as r, EachOpts as s, EachBox as t, each as u };