Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

TL7e: a clip's Combo animation, CapCut's third kind. sdk/video edges.ts gains COMBOS, seven waves (pulse, sway, float, shake, swing, spin, flicker), each a property's values over one cycle eased between, comboStyle and joinStyles; <Transition combo={{ kind, frames }}> moves the part throughout with its in and out. sdk/timeline: Clip.combo { kind, length } (a cycle's frames: the clip's length plays it once, fewer loop it), the set op's combo, animStyle drawing it from the palette's combos, a plugin's Combos as data (timeline.combos, checked), and a composition's <Transition combo> as an edge op with side combo, read back. fromSequences now reads a sequence's in and out that no cut's transition takes as the clip's own In and Out (TL7d), so they survive the host's re-read. 90 SDK tests, 5 Transition conformance tests; the manual regenerated

shinyobjectz9f553d6ecc7a
diff --git a/docs/manual/reference/sdk/editor.md b/docs/manual/reference/sdk/editor.md
index d3447ea3..14748f90 100644
--- a/docs/manual/reference/sdk/editor.md
+++ b/docs/manual/reference/sdk/editor.md
@@ -21,7 +21,7 @@ built, edited and undone.
import { ahead, animStyle, apply, applyAll } from "raea/editor"
```
-`raea/editor` exports 53 functions, 14 values, 35 types. Bevy's counterpart: `raea's own; Bevy has no timeline editor`. Source: [sdk/raea/src/editor.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/editor.ts).
+`raea/editor` exports 53 functions, 16 values, 37 types. Bevy's counterpart: `raea's own; Bevy has no timeline editor`. Source: [sdk/raea/src/editor.ts](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/editor.ts).
## Functions
@@ -36,11 +36,11 @@ function ahead(length: number, kept: Range[], playhead: number, chunk: number):
### `animStyle`
-The clip's style `into` frames from its start, coming in by its In and going out by its Out, each over no more
-of it than it has. Empty when neither plays there.
+The clip's style `into` frames from its start: coming in by its In, going out by its Out (each over no more of it
+than it has) and moving by its Combo, one of `combos` (a plugin's among them). Empty when none plays there.
```ts
-function animStyle(c: Clip, into: number): EdgeStyle
+function animStyle(c: Clip, into: number, combos?: ComboKind[]): EdgeStyle
```
### `apply`
@@ -274,7 +274,7 @@ function next(t: Timeline, frame: number): number | undefined
Everything offered: raea's own, then each plugin's in order (a name a plugin before it took stays that one's).
```ts
-function palette(plugins?: Adds[]): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; tracks: TrackKindInfo[]; effects: EffectInfo[]; texts: TextStyle[]; tools: Preset[]; snaps: SnapGrid[]; }
+function palette(plugins?: Adds[]): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; combos: ComboKind[]; tracks: TrackKindInfo[]; effects: EffectInfo[]; texts: TextStyle[]; tools: Preset[]; snaps: SnapGrid[]; }
```
### `partsFilter`
@@ -483,6 +483,12 @@ function without(ranges: Range[], cut: Range[]): Range[]
The transitions a composition's <Transition> draws (sdk/video edges.ts).
+### `COMBO_KINDS`
+
+### `COMBOS`
+
+raea's own Combos: the kinds <Transition combo> draws. A plugin adds its own as data the same way.
+
### `CURVES`
CapCut's curve presets, as points over the source; a plugin adds its own.
@@ -539,6 +545,7 @@ What one plugin adds.
| `eases` | `Record<string, Ease>` | easings of its own, by name |
| `curves` | `Record<string, SpeedPoint[]>` | speed curves of its own, by name |
| `transitions` | `TransitionKind[]` | transitions of its own |
+| `combos` | `ComboKind[]` | Combos of its own: how a clip moves over one cycle, as data the timeline's preview draws |
| `tracks` | `TrackKindInfo[]` | kinds of track of its own: a clip posted or added on one is drawn and edited like any other |
| `effects` | `EffectInfo[]` | effects of its own (TL7b, TL11a), each drawn by its parts: CSS filter functions from amount 0 to amount 1 |
| `texts` | `TextStyle[]` | text styles of its own (TL7c, TL11a) |
@@ -589,6 +596,7 @@ A span of something on a track: footage, a sound, words, a composition's sequenc
| `fadeOut` | `Frames` | sound: how long it fades out to its end |
| `enter` | `Anim` | the picture or words: how it comes in over its first frames (TL7d, CapCut's In animation) |
| `exit` | `Anim` | the picture or words: how it goes out over its last frames (TL7d, CapCut's Out animation) |
+| `combo` | `Anim` | the picture or words: how it moves over its whole length (TL7e, CapCut's Combo and its text Loop), a cycle every `length` frames from its first; its own length plays it once |
| `at` | `string` | its element in the code |
| `markers` | `Marker[]` | markers on the clip itself, in frames from its start |
| `inside` | `{ kind: TrackKind; clip: Clip }[]` | a compound clip: the clips it holds, each with the kind of track it came from, their starts in frames from this clip's own start |
@@ -605,6 +613,32 @@ turned up or down (raea-feed host/clips.ts).
| `offset` (required) | `number` | where in its file it starts playing, in seconds |
| `gainDb` (required) | `number` | its level change, in dB (0 as recorded) |
+### `ComboKind`
+
+A kind of Combo: its name, what the person sees, and its wave.
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `kind` (required) | `string` | its name, as code writes it |
+| `title` (required) | `string` | what the person sees |
+| `wave` (required) | `ComboWave` | how it moves over one cycle |
+| `linear` | `boolean` | straight from value to value, not eased: a spin that keeps turning |
+
+### `ComboWave`
+
+How a part moves over one cycle of a Combo: each
+property's values, evenly spaced over the cycle and eased between, the cycle starting again where it ends. x and y
+move it by a share of its own size in percent, rotate turns it in degrees, scale sizes it, opacity fades it. A wave
+that ends where it starts plays once over the part as CapCut's Combo does, and loops seamlessly as its text Loop does.
+
+| Field | Type | What it is |
+| --- | --- | --- |
+| `x` | `number[]` | across, in percent of its width |
+| `y` | `number[]` | down, in percent of its height |
+| `scale` | `number[]` | its size, 1 as it is |
+| `rotate` | `number[]` | turned, in degrees |
+| `opacity` | `number[]` | how much of it shows, 0 to 1 |
+
### `Ease`
How a value travels from one key to the next: a straight line, no travel (it holds, then jumps), or a cubic
@@ -778,6 +812,7 @@ the lane it sits on (nested ones below their parent, overlapping ones apart), an
| `effect` | `{ kind: string; amount: number; /** a plugin's: the parts that draw it */ parts?: Effec…` | the effect it puts on the picture under it, when an <Effect> is all it holds: an effect clip |
| `in` | `{ kind: string; frames: number }` | how it comes in and goes out: its <Transition>'s in and out |
| `out` | `{ kind: string; frames: number }` | how it goes out: its <Transition>'s out |
+| `combo` | `{ kind: string; frames: number }` | how it moves throughout: its <Transition>'s combo, a cycle every `frames` |
| `media` | `"video" \| "audio"` | a <Video> or an <Audio> of its own: it plays where the sequence it is in does, from `startFrom` of its file, at its own level |
| `startFrom` | `number` | its media's first frame used, in frames of its file |
| `volume` | `number` | its media's level, 1 as recorded |
diff --git a/docs/manual/reference/sdk/index.md b/docs/manual/reference/sdk/index.md
index 633b9343..a915f1ec 100644
--- a/docs/manual/reference/sdk/index.md
+++ b/docs/manual/reference/sdk/index.md
@@ -61,7 +61,7 @@ Footage, pictures, sound, words and colour, and the timeline they are edited on.
| [`raea/image`](image.md) | Pictures on the page and in the world, and texture atlases packed from them. | 3 components, 1 class, 5 types |
| [`raea/asset`](asset.md) | Files the project holds and assets made for it: staticFile, generated sound and music, and glTF bytes. | 9 functions, 1 value, 8 types |
| [`raea/color`](color.md) | Bevy's colour types: Srgba, LinearRgba, Hsla, Oklab, Oklch and the rest, with their conversions. | 2 functions, 7 classes |
-| [`raea/editor`](editor.md) | The timeline the feed edits a film, a scene or a sound on, as data: tracks, clips, keys and markers, every edit an operation with its inverse, a film's scenes read in (fromRender) and its cut read back out as segments (segmentsOf). No React and no DOM: an agent's script, the app's host and a test use the same model the app's timeline does. | 53 functions, 14 values, 35 types |
+| [`raea/editor`](editor.md) | The timeline the feed edits a film, a scene or a sound on, as data: tracks, clips, keys and markers, every edit an operation with its inverse, a film's scenes read in (fromRender) and its cut read back out as segments (segmentsOf). No React and no DOM: an agent's script, the app's host and a test use the same model the app's timeline does. | 53 functions, 16 values, 37 types |
## 3D
diff --git a/docs/manual/reference/sdk/raea.md b/docs/manual/reference/sdk/raea.md
index 1d1aff13..d9edea32 100644
--- a/docs/manual/reference/sdk/raea.md
+++ b/docs/manual/reference/sdk/raea.md
@@ -262,12 +262,13 @@ Also takes the props of [`StaggerProps`](animation.md#staggerprops) (`each`, `gr
### `Transition`
-Its children, coming in over the part's first frames and going out over its last.
+Its children, coming in over the part's first frames, going out over its last, and moving by a Combo throughout.
| Prop | Type | What it does |
| --- | --- | --- |
| `in` | `TransitionEdge` | over the part's first frames |
| `out` | `TransitionEdge` | over the part's last frames |
+| `combo` | `ComboLoop` | a Combo over the whole part: a cycle every `frames`, from its first frame |
| `children` | `ReactNode` | the part it brings in and takes out: what the <Sequence> holds |
### `Video`
diff --git a/docs/timeline.feature b/docs/timeline.feature
index 412ae047..6d7069d8 100644
--- a/docs/timeline.feature
+++ b/docs/timeline.feature
@@ -76,7 +76,7 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
playback's mapping, readers and writers for a composition's sequences (its footage and sound, its text, its
effects, a recording, a project's file), a film's scenes and a sound's tracks, the palette a plugin adds to; 77
tests), and in
- sdk/video <Nudge keys>, <Transition in out> (fade, slide, wipe, zoom), <Effect kind amount in out> (blur, mono,
+ sdk/video <Nudge keys>, <Transition in out combo> (fade, slide, wipe, zoom; a Combo's seven waves), <Effect kind amount in out> (blur, mono,
sepia, vivid, faded, contrast, bright, dark, invert, hue: a filter on the picture under it) and a <Video>'s or
an <Audio>'s speedCurve (the mixer carries its sound through the changing rate as one voice). In raea-feed, draft
PR #19: the new timeline is the timeline (localStorage raea.timeline-sdk = 0 brings the old strip back); 36 browser
@@ -128,7 +128,11 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
and its frames, in the clip's row; a ramp on the clip; the film's picture and words over it show it
at once, drawn by sdk/video edges.ts, the table <Transition> now draws from too; split, each half
keeps its own end's; never longer than the clip; in a composition the sequence's <Transition>
- edge, taken off with no frames; Send says how it comes in or goes out; Combo not built), a
+ edge, taken off with no frames, read back as the clip's own where no cut's transition takes it;
+ Send says how it comes in or goes out), TL7e (a Combo: seven of raea's, as waves in sdk/video
+ edges.ts, and a plugin's as data; its cycle starts at the clip's length, playing once, and loops
+ when shorter; with the In and Out at once on the film's picture and words; a line with a tick a
+ cycle on the clip; <Transition combo> in a composition, written and read back), a
plugin's effects as data (timeline.effects in its manifest: parts
of CSS filter functions, drawn by <Effect parts> and by the preview alike), TL8a
(waveform, level line, fades; Cmd+. and Cmd+, step the level by 0.1 dB, or key it at the
@@ -413,8 +417,18 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
Then it plays over the clip's own first or last frames, drawn as a ramp at that end of the clip, and the picture
shows it at once
And split, the first part keeps the In and the second the Out; it is never longer than the clip
- And in a composition it is the sequence's own <Transition in out>, the same component a cut's transition writes
- And a looping Combo animation over the whole clip is CapCut's third kind, not built yet
+ And in a composition it is the sequence's own <Transition in out>, the same component a cut's transition writes,
+ and read back from it as the clip's own wherever no cut's transition takes it
+
+ Scenario: TL7e. A clip's Combo animation
+ Given a clip of footage, a still or text picked
+ When I give it a Combo (CapCut's third kind: pulse, sway, float, shake, swing, spin, flicker, or a plugin's)
+ Then it moves over the clip's whole length, a cycle every so many frames: the clip's own length (what it starts
+ at) plays it once, as CapCut's Combo does, and fewer loop it, as CapCut's text Loop does
+ And it plays with the clip's In and Out at once, drawn as a line along the clip with a tick at each cycle
+ And a Combo is data, a wave of the clip's x, y, scale, rotate and opacity over one cycle, so a plugin adds one in
+ its manifest and the preview draws it
+ And in a composition it is the sequence's <Transition combo>, written and read back
Rule: TL8. Sound
Scenario: TL8a. The waveform, the volume line and fades
diff --git a/sdk/raea/conformance/transition.test.tsx b/sdk/raea/conformance/transition.test.tsx
index a15ebd00..64cb9fed 100644
--- a/sdk/raea/conformance/transition.test.tsx
+++ b/sdk/raea/conformance/transition.test.tsx
@@ -1,7 +1,7 @@
// <Transition>: how a part comes in and goes out, as the timeline writes a transition on a cut
// (docs/timeline.feature TL7a).
import { describe, expect, test } from "bun:test";
-import { Transition, transitionAt, transitionStyle } from "@raea/video/transition";
+import { COMBOS, comboStyle, joinStyles, Transition, transitionAt, transitionStyle } from "@raea/video/transition";
import { Sequence } from "../src";
import { renderFrame } from "../src/test";
@@ -34,3 +34,24 @@ describe("a part comes in over its first frames and goes out over its last", ()
expect(() => renderFrame(<Transition in={{ kind: "spin" as never, frames: 10 }}>x</Transition>, { ...opts, frame: 0 })).toThrow(/kind is one of/);
});
});
+
+describe("a Combo moves the part over its whole length (TL7e)", () => {
+ const pulse = COMBOS.find((c) => c.kind === "pulse");
+ test("its wave eased between evenly spaced values, at rest where a cycle starts and ends, looping", () => {
+ expect(comboStyle(pulse, 0, 60)).toEqual({ transform: "scale(1)" });
+ expect(comboStyle(pulse, 30, 60)).toEqual({ transform: "scale(1.08)" });
+ expect(comboStyle(pulse, 15, 60)).toEqual({ transform: "scale(1.04)" });
+ expect(comboStyle(pulse, 90, 60)).toEqual(comboStyle(pulse, 30, 60));
+ // a spin keeps turning at one pace
+ expect(comboStyle(COMBOS.find((c) => c.kind === "spin"), 15, 60)).toEqual({ transform: "rotate(90deg)" });
+ expect(comboStyle(undefined, 15, 60)).toEqual({});
+ });
+
+ test("in a <Sequence> with its In and Out: the moves side by side, the fades multiplied", () => {
+ const at = (frame: number) => renderFrame(<Sequence from={0} durationInFrames={60}><Transition in={{ kind: "fade", frames: 10 }} combo={{ kind: "pulse", frames: 60 }}><p>hi</p></Transition></Sequence>, { ...opts, frame });
+ expect(at(4)).toContain("opacity:0.5");
+ expect(at(30)).toContain("scale(1.08)");
+ expect(joinStyles({ transform: "a", opacity: 0.5 }, { transform: "b", opacity: 0.5, clipPath: "c" })).toEqual({ transform: "a b", opacity: 0.25, clipPath: "c" });
+ expect(() => renderFrame(<Transition combo={{ kind: "wobble", frames: 10 }}>x</Transition>, { ...opts, frame: 0 })).toThrow(/combo.kind is one of/);
+ });
+});
diff --git a/sdk/timeline/src/anim.ts b/sdk/timeline/src/anim.ts
index 2c475c91..e5747f25 100644
--- a/sdk/timeline/src/anim.ts
+++ b/sdk/timeline/src/anim.ts
@@ -1,16 +1,17 @@
-// A clip's own In and Out animations as the picture shows them (docs/timeline.feature TL7d): the edges a
-// composition's <Transition> draws (sdk/video edges.ts), so the timeline's preview of a film matches the render.
-import { edgesStyle, type EdgeStyle, TRANSITION_KINDS, type TransitionKind } from "@raea/video/edges"
+// A clip's own animations as the picture shows them (docs/timeline.feature TL7d, TL7e): the In and Out edges and the
+// Combo a composition's <Transition> draws (sdk/video edges.ts), so the timeline's preview of a film matches the render.
+import { COMBOS, type ComboKind, comboStyle, edgesStyle, type EdgeStyle, joinStyles, TRANSITION_KINDS, type TransitionKind } from "@raea/video/edges"
import type { Anim, Clip, Frames } from "./model"
-export type { EdgeStyle } from "@raea/video/edges"
+export { COMBO_KINDS, COMBOS, type ComboKind, type ComboWave, type EdgeStyle } from "@raea/video/edges"
/** raea's own kind, or a fade for a plugin's, which only its own code draws. */
const kindOf = (k: string): TransitionKind => (TRANSITION_KINDS.includes(k as TransitionKind) ? (k as TransitionKind) : "fade")
-/** The clip's style `into` frames from its start, coming in by its In and going out by its Out, each over no more
- * of it than it has. Empty when neither plays there. */
-export function animStyle(c: Clip, into: Frames): EdgeStyle {
+/** The clip's style `into` frames from its start: coming in by its In, going out by its Out (each over no more of it
+ * than it has) and moving by its Combo, one of `combos` (a plugin's among them). Empty when none plays there. */
+export function animStyle(c: Clip, into: Frames, combos: ComboKind[] = COMBOS): EdgeStyle {
const edge = (a?: Anim) => (a ? { kind: kindOf(a.kind), frames: Math.min(a.length, c.length) } : undefined)
- return edgesStyle(edge(c.enter), edge(c.exit), into, c.length)
+ const combo = c.combo ? comboStyle(combos.find((k) => k.kind === c.combo!.kind), into, c.combo.length) : {}
+ return joinStyles(edgesStyle(edge(c.enter), edge(c.exit), into, c.length), combo)
}
diff --git a/sdk/timeline/src/model.ts b/sdk/timeline/src/model.ts
index 7eb037d1..9c871153 100644
--- a/sdk/timeline/src/model.ts
+++ b/sdk/timeline/src/model.ts
@@ -102,6 +102,9 @@ export interface Clip {
enter?: Anim
/** the picture or words: how it goes out over its last frames (TL7d, CapCut's Out animation) */
exit?: Anim
+ /** the picture or words: how it moves over its whole length (TL7e, CapCut's Combo and its text Loop), a cycle every
+ * `length` frames from its first; its own length plays it once */
+ combo?: Anim
/** its element in the code (file:line:col, docs/editing.feature E2) */
at?: string
/** markers on the clip itself, in frames from its start (TL2e) */
diff --git a/sdk/timeline/src/ops.ts b/sdk/timeline/src/ops.ts
index 27a24315..0f0578da 100644
--- a/sdk/timeline/src/ops.ts
+++ b/sdk/timeline/src/ops.ts
@@ -34,7 +34,7 @@ export type Op =
/** a still of the frame under `at` on a clip (the main track's, when none is named), `length` frames long, put in
* there: the clip is split and the still goes between its halves (TL3h) */
| { op: "freeze"; at: Frames; length: Frames; id?: string }
- | { op: "set"; id: string; set: Partial<Pick<Clip, "name" | "off" | "volume" | "fadeIn" | "fadeOut" | "speed" | "group" | "reverse">> & { curve?: SpeedPoint[] | null; props?: Record<string, Value | boolean>; /** its In or Out animation (TL7d); null takes it off */ enter?: Anim | null; exit?: Anim | null } }
+ | { op: "set"; id: string; set: Partial<Pick<Clip, "name" | "off" | "volume" | "fadeIn" | "fadeOut" | "speed" | "group" | "reverse">> & { curve?: SpeedPoint[] | null; props?: Record<string, Value | boolean>; /** its In or Out animation (TL7d); null takes it off */ enter?: Anim | null; exit?: Anim | null; /** its Combo (TL7e), a cycle every `length` frames; null takes it off */ combo?: Anim | null } }
/** a property's key at a frame of its clip: made, or its value (and ease) changed (TL5a) */
| { op: "key"; id: string; prop: string; at: Frames; value: Value; ease?: Ease }
| { op: "unkey"; id: string; prop: string; at: Frames }
@@ -264,7 +264,7 @@ function run(t: Timeline, op: Exclude<Op, { op: "restore" }>): Timeline {
}
case "set": {
const { clip } = open(t, op.id)
- const { props, curve, enter, exit, ...rest } = op.set
+ const { props, curve, enter, exit, combo, ...rest } = op.set
let c: Clip = { ...clip, ...rest, ...(props && { props: { ...clip.props, ...props } }) }
const source = shown(clip)
if (curve !== undefined || (rest.speed !== undefined && rest.speed !== clip.speed)) {
@@ -273,8 +273,8 @@ function run(t: Timeline, op: Exclude<Op, { op: "restore" }>): Timeline {
// the same frames of source, at the new pace
c = { ...c, curve: points, shows: points ? source : undefined, length: Math.max(1, whole(points ? played(points, source) : source / speedOf(c))) }
}
- // an In or Out animation (TL7d): a kind, over no more of the clip than it has; null takes it off
- for (const [side, a] of [["enter", enter], ["exit", exit]] as const) {
+ // an In or Out animation (TL7d) or a Combo's cycle (TL7e): a kind, over no more of the clip than it has; null takes it off
+ for (const [side, a] of [["enter", enter], ["exit", exit], ["combo", combo]] as const) {
if (a === undefined) continue
if (a !== null && (typeof a.kind !== "string" || !a.kind || !(a.length >= 1))) no("an animation is a kind and at least one frame")
const { [side]: _, ...without } = c
diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.ts
index d3647146..cc7f1be5 100644
--- a/sdk/timeline/src/read.ts
+++ b/sdk/timeline/src/read.ts
@@ -5,7 +5,7 @@
import { type Clip, type Ease, empty, end, find, type Frames, type Key, type Timeline, type Track } from "./model"
import { apply, type Op } from "./ops"
import { EFFECTS, type EffectPart, type TextStyle, textStyleError } from "./registry"
-import { TRANSITION_KINDS } from "@raea/video/edges"
+import { COMBO_KINDS, TRANSITION_KINDS } from "@raea/video/edges"
/** A text clip's style, kept in its props as JSON: read back when it is well formed. */
export function textStyleOf(v: unknown): TextStyle | undefined {
@@ -65,6 +65,8 @@ export interface SeqRow {
in?: { kind: string; frames: number }
/** how it goes out: its <Transition>'s out */
out?: { kind: string; frames: number }
+ /** how it moves throughout: its <Transition>'s combo, a cycle every `frames` (TL7e) */
+ combo?: { kind: string; frames: number }
/** a <Video> or an <Audio> of its own (TL0c): it plays where the sequence it is in does, from `startFrom` of its
* file, at its own level */
media?: "video" | "audio"
@@ -117,8 +119,9 @@ export type SeqEdit =
| { op: "voice"; at: number; frames: number; file: string }
/** an effect clip's kind or amount */
| { op: "fx"; i: number; kind?: string; amount?: number }
- /** how it comes in ("in") or goes out ("out"): its <Transition>'s edge set, or taken off with 0 frames (TL7a) */
- | { op: "edge"; i: number; side: "in" | "out"; kind: string; frames: number }
+ /** how it comes in ("in"), goes out ("out") or moves throughout ("combo", TL7e): its <Transition>'s prop set, or
+ * taken off with 0 frames (TL7a) */
+ | { op: "edge"; i: number; side: "in" | "out" | "combo"; kind: string; frames: number }
/** a <Video>'s or an <Audio>'s own level (TL8a) */
| { op: "level"; i: number; volume: number }
/** a <Video>'s own sound taken out (TL4c): the <Video> muted, and an <Audio> of the same file, from the same place
@@ -166,6 +169,17 @@ export function fromSequences(rows: SeqRow[], fps: number): Timeline {
return out && into && out.kind === into.kind ? [{ id: `x-${c.id}`, kind: out.kind, after: c.id, length: out.frames + into.frames }] : []
}),
)
+ // an edge no cut's transition took is the clip's own In or Out animation (TL7d)
+ for (const k of tracks) {
+ k.clips = k.clips.map((c) => {
+ const r = by.get(c.id), before = k.clips.find((o) => end(o) === c.start)
+ const anim = (e?: { kind: string; frames: number }) => (e && e.frames > 0 ? { kind: e.kind, length: Math.min(e.frames, c.length) } : undefined)
+ const enter = before && transitions.some((x) => x.after === before.id) ? undefined : anim(r?.in)
+ const exit = transitions.some((x) => x.after === c.id) ? undefined : anim(r?.out)
+ const combo = r?.combo && r.combo.frames > 0 ? { kind: r.combo.kind, length: r.combo.frames } : undefined
+ return { ...c, ...(enter && { enter }), ...(exit && { exit }), ...(combo && { combo }) }
+ })
+ }
// footage and sound of their own: a track each kind, more where they play at once; a sound's below the picture
const mediaTracks = (kind: "video" | "audio"): Track[] => {
const out: Track[] = []
@@ -294,19 +308,19 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {
const look: SeqLook = { ...Object.fromEntries(KEYED.flatMap((k) => (num(k) === undefined ? [] : [[k, num(k)]]))), ...(p.mirror === true && { mirror: true }), ...(crop.some((v) => v > 0) && { crop }) }
return each([op.id], (r) => ({ op: "nudge", i: r.i, look }))
}
- // its In and Out animations (TL7d): its <Transition>'s edges, as a cut's transition writes them
- if (only.length && only.every((k) => k === "enter" || k === "exit")) {
+ // its In and Out animations (TL7d) and its Combo (TL7e): its <Transition>'s edges, as a cut's transition writes them
+ if (only.length && only.every((k) => k === "enter" || k === "exit" || k === "combo")) {
const after = apply(t, op)
if (!after.ok) return { why: after.why }
const now = find(after.timeline, op.id)?.clip
const out: SeqEdit[] = []
- for (const [key, side] of [["enter", "in"], ["exit", "out"]] as const) {
+ for (const [key, side] of [["enter", "in"], ["exit", "out"], ["combo", "combo"]] as const) {
if (!only.includes(key)) continue
- const a = now?.[key]
- if (a && !CODE_KINDS.includes(a.kind)) return { why: `a composition draws ${CODE_KINDS.join(", ")}: "${a.kind}" isn't one its <Transition> has` }
+ const a = now?.[key], kinds = key === "combo" ? COMBO_KINDS : CODE_KINDS
+ if (a && !kinds.includes(a.kind)) return { why: `a composition draws ${kinds.join(", ")}: "${a.kind}" isn't one its <Transition> has` }
const r = row(op.id)
if (!r) return { why: "only a composition's sequence comes in or goes out here" }
- out.push({ op: "edge", i: r.i, side, kind: a?.kind ?? "fade", frames: a?.length ?? 0 })
+ out.push({ op: "edge", i: r.i, side, kind: a?.kind ?? (key === "combo" ? COMBO_KINDS[0] : "fade"), frames: a?.length ?? 0 })
}
return out
}
diff --git a/sdk/timeline/src/registry.ts b/sdk/timeline/src/registry.ts
index 4f870f3b..b63e412b 100644
--- a/sdk/timeline/src/registry.ts
+++ b/sdk/timeline/src/registry.ts
@@ -6,6 +6,8 @@ import { type Ease, type SpeedPoint, under } from "./model"
import { CURVES, FASTEST, SLOWEST } from "./speed"
// raea's effects (TL7b): the one table the engine's <Effect> draws from, so a preview here is what a render shows
import { EFFECTS, effectFilter, type EffectKind, type EffectPart, effectPartsError, partsFilter } from "@raea/video/effects"
+// raea's Combos (TL7e): the table <Transition combo> draws, a plugin's added to it as data of the same shape
+import { COMBOS, type ComboKind } from "@raea/video/edges"
export { EFFECTS, effectFilter, type EffectKind, type EffectPart, partsFilter }
@@ -121,6 +123,8 @@ export interface Adds {
curves?: Record<string, SpeedPoint[]>
/** transitions of its own (TL7a) */
transitions?: TransitionKind[]
+ /** Combos of its own (TL7e): how a clip moves over one cycle, as data the timeline's preview draws */
+ combos?: ComboKind[]
/** kinds of track of its own (TL11a): a clip posted or added on one is drawn and edited like any other */
tracks?: TrackKindInfo[]
/** effects of its own (TL7b, TL11a), each drawn by its parts: CSS filter functions from amount 0 to amount 1 */
@@ -155,12 +159,26 @@ const isEase = (e: unknown): e is Ease => e === "linear" || e === "hold" || (Arr
const isCurve = (c: unknown): c is SpeedPoint[] =>
Array.isArray(c) && c.length >= 2 && c.every((p) => p && typeof p.at === "number" && p.at >= 0 && p.at <= 1 && typeof p.speed === "number" && p.speed >= SLOWEST && p.speed <= FASTEST)
+const WAVE = ["x", "y", "scale", "rotate", "opacity"]
+/** Why a plugin's Combo isn't well formed, or nothing when it is. */
+function comboError(x: unknown): string | undefined {
+ const c = x as Partial<ComboKind> | null
+ if (!c || typeof c.kind !== "string" || !/^[a-z][a-z0-9-]*$/.test(c.kind) || typeof c.title !== "string" || !c.title.trim()) return "is { kind, title, wave }: kind in lowercase letters, digits and dashes, title what the person sees"
+ if (!c.wave || typeof c.wave !== "object" || !Object.keys(c.wave).length) return `(${c.kind}): its wave is an object of ${WAVE.join(", ")}`
+ for (const [k, v] of Object.entries(c.wave)) {
+ if (!WAVE.includes(k)) return `(${c.kind}): a wave moves ${WAVE.join(", ")}, not ${k}`
+ if (!Array.isArray(v) || !v.length || v.length > 64 || !v.every((n) => typeof n === "number" && Number.isFinite(n))) return `(${c.kind}): wave.${k} is 1 to 64 numbers over one cycle`
+ }
+ if (c.linear !== undefined && typeof c.linear !== "boolean") return `(${c.kind}): linear is true or false`
+ return undefined
+}
+
/** A plugin's additions as written in its manifest, checked: what is well formed, and why the rest isn't. */
export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
const errors: string[] = []
const adds: Adds = {}
if (raw === undefined) return { adds, errors }
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { adds, errors: ["timeline is an object: { eases, curves, transitions, tracks, effects, texts, tools, snaps }"] }
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { adds, errors: ["timeline is an object: { eases, curves, transitions, combos, tracks, effects, texts, tools, snaps }"] }
const r = raw as Record<string, unknown>
const named = (v: unknown, what: string): [string, unknown][] => (v === undefined ? [] : v && typeof v === "object" && !Array.isArray(v) ? Object.entries(v) : (errors.push(`timeline.${what} is an object of named ${what}`), []))
for (const [name, e] of named(r.eases, "eases")) {
@@ -183,6 +201,16 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
else (adds.transitions ??= []).push({ kind: t.kind, title: t.title })
}
}
+ if (r.combos !== undefined) {
+ if (!Array.isArray(r.combos)) errors.push("timeline.combos is a list of { kind, title, wave }")
+ else
+ for (const [i, x] of r.combos.entries()) {
+ const why = comboError(x)
+ if (why) errors.push(`timeline.combos[${i}] ${why}`)
+ else if (COMBOS.some((o) => o.kind === (x as ComboKind).kind)) errors.push(`timeline.combos[${i}]: raea has a combo "${(x as ComboKind).kind}"`)
+ else (adds.combos ??= []).push(x as ComboKind)
+ }
+ }
if (r.tracks !== undefined) {
if (!Array.isArray(r.tracks)) errors.push("timeline.tracks is a list of { kind, title }")
else
@@ -237,8 +265,8 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
}
/** Everything offered: raea's own, then each plugin's in order (a name a plugin before it took stays that one's). */
-export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; tracks: TrackKindInfo[]; /** the effects a clip of its own puts on the picture (TL7b) */ effects: EffectInfo[]; /** the ways words are put on the picture (TL7c) */ texts: TextStyle[]; /** a plugin's tools: presets for the picked clips */ tools: Preset[]; /** a plugin's snap grids */ snaps: SnapGrid[] } {
- const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS], tracks = [...TRACKS]
+export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; curves: Record<string, SpeedPoint[]>; transitions: TransitionKind[]; /** the ways a clip moves over its whole length (TL7e) */ combos: ComboKind[]; tracks: TrackKindInfo[]; /** the effects a clip of its own puts on the picture (TL7b) */ effects: EffectInfo[]; /** the ways words are put on the picture (TL7c) */ texts: TextStyle[]; /** a plugin's tools: presets for the picked clips */ tools: Preset[]; /** a plugin's snap grids */ snaps: SnapGrid[] } {
+ const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS], combos = [...COMBOS], tracks = [...TRACKS]
const effects: EffectInfo[] = EFFECTS.map(({ kind, title }) => ({ kind, title }))
const texts = [...TEXTS]
const tools: Preset[] = [], snaps: SnapGrid[] = []
@@ -246,6 +274,7 @@ export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; cu
for (const [n, e] of Object.entries(p.eases ?? {})) if (!(n in eases)) eases[n] = e
for (const [n, c] of Object.entries(p.curves ?? {})) if (!(n in curves)) curves[n] = c
for (const t of p.transitions ?? []) if (!transitions.some((o) => o.kind === t.kind)) transitions.push(t)
+ for (const c of p.combos ?? []) if (!combos.some((o) => o.kind === c.kind)) combos.push(c)
for (const e of p.effects ?? []) if (!effects.some((o) => o.kind === e.kind)) effects.push(e)
for (const x of p.texts ?? []) if (!texts.some((o) => o.kind === x.kind)) texts.push(x)
for (const x of p.tools ?? []) if (!tools.some((o) => o.id === x.id)) tools.push(x)
@@ -256,5 +285,5 @@ export function palette(plugins: Adds[] = []): { eases: Record<string, Ease>; cu
if (t.under) under.add(t.kind)
}
}
- return { eases, curves, transitions, tracks, effects, texts, tools, snaps }
+ return { eases, curves, transitions, combos, tracks, effects, texts, tools, snaps }
}
diff --git a/sdk/timeline/test/anim.test.ts b/sdk/timeline/test/anim.test.ts
index f90f59e0..fb47bf53 100644
--- a/sdk/timeline/test/anim.test.ts
+++ b/sdk/timeline/test/anim.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
-import { animStyle, apply, type Clip, empty, find, seqEdits, type Timeline } from "../src"
+import { animStyle, apply, type Clip, empty, find, fromSequences, seqEdits, type Timeline } from "../src"
const film = (): Timeline => ({
...empty(30),
@@ -49,4 +49,43 @@ describe("TL7d: a clip's own In and Out animations", () => {
expect(seqEdits(t, { op: "set", id: "seq-0", set: { exit: null } })).toEqual([{ op: "edge", i: 0, side: "out", kind: "fade", frames: 0 }])
expect(seqEdits(t, { op: "set", id: "seq-0", set: { enter: { kind: "glitch", length: 12 } } })).toEqual({ why: 'a composition draws fade, slide, wipe, zoom: "glitch" isn\'t one its <Transition> has' })
})
+
+ test("TL7e: a Combo over the whole clip, a cycle every so many frames, with its In and Out", () => {
+ const t = done(film(), { op: "set", id: "a", set: { combo: { kind: "pulse", length: 60 }, enter: { kind: "fade", length: 10 } } })
+ expect(clip(t, "a").combo).toEqual({ kind: "pulse", length: 60 })
+ const c = clip(t, "a")
+ expect(animStyle(c, 30)).toEqual({ transform: "scale(1.08)" })
+ expect(animStyle(c, 4)).toEqual({ opacity: 0.5, transform: "scale(1.004)" })
+ // a plugin's Combo draws from its own wave; one the palette doesn't have draws nothing
+ const wobble = { kind: "wobble", title: "Wobble", wave: { x: [0, 10, 0] } }
+ const w = done(t, { op: "set", id: "a", set: { combo: { kind: "wobble", length: 20 }, enter: null } })
+ expect(animStyle(clip(w, "a"), 10, [wobble])).toEqual({ transform: "translate(10%, 0%)" })
+ expect(animStyle(clip(w, "a"), 10)).toEqual({})
+ // split, both parts keep it; null takes it off
+ const s = done(t, { op: "split", at: 30, ids: ["a"] })
+ expect([clip(s, "a").combo, clip(s, "a+").combo]).toEqual([{ kind: "pulse", length: 60 }, { kind: "pulse", length: 60 }])
+ expect("combo" in clip(done(t, { op: "set", id: "a", set: { combo: null } }), "a")).toBe(false)
+ })
+
+ test("TL7e: in a composition it is the sequence's <Transition combo>, read back as the clip's", () => {
+ const t: Timeline = { ...empty(30), tracks: [{ id: "main", kind: "main", clips: [{ id: "seq-0", kind: "sequence", start: 0, length: 60 }] }] }
+ expect(seqEdits(t, { op: "set", id: "seq-0", set: { combo: { kind: "sway", length: 30 } } })).toEqual([{ op: "edge", i: 0, side: "combo", kind: "sway", frames: 30 }])
+ expect(seqEdits(t, { op: "set", id: "seq-0", set: { combo: null } })).toEqual([{ op: "edge", i: 0, side: "combo", kind: "pulse", frames: 0 }])
+ expect(seqEdits(t, { op: "set", id: "seq-0", set: { combo: { kind: "wobble", length: 30 } } })).toEqual({ why: expect.stringContaining('"wobble" isn\'t one its <Transition> has') })
+ const back = fromSequences([{ i: 0, name: "Sequence", from: 0, to: 60, lane: 0, combo: { kind: "sway", frames: 30 } }], 30)
+ expect(back.tracks[0].clips[0].combo).toEqual({ kind: "sway", length: 30 })
+ })
+
+ test("read back from the code: an edge a cut's transition didn't take is the clip's own", () => {
+ const row = (i: number, from: number, extra = {}) => ({ i, name: "Sequence", from, to: from + 60, lane: 0, ...extra })
+ // A comes in by a zoom; A and B share a slide on their cut; B goes out by a wipe
+ const t = fromSequences([row(0, 0, { in: { kind: "zoom", frames: 12 }, out: { kind: "slide", frames: 8 } }), row(1, 60, { in: { kind: "slide", frames: 7 }, out: { kind: "wipe", frames: 90 } })], 30)
+ expect(t.transitions).toEqual([{ id: "x-seq-0", kind: "slide", after: "seq-0", length: 15 }])
+ const [a, b] = t.tracks[0].clips
+ expect([a.enter, a.exit, b.enter, b.exit]).toEqual([{ kind: "zoom", length: 12 }, undefined, undefined, { kind: "wipe", length: 60 }])
+ // edges of different kinds on a cut are each clip's own
+ const apart = fromSequences([row(0, 0, { out: { kind: "fade", frames: 8 } }), row(1, 60, { in: { kind: "zoom", frames: 7 } })], 30)
+ expect(apart.transitions).toEqual([])
+ expect([apart.tracks[0].clips[0].exit, apart.tracks[0].clips[1].enter]).toEqual([{ kind: "fade", length: 8 }, { kind: "zoom", length: 7 }])
+ })
})
diff --git a/sdk/timeline/test/registry.test.ts b/sdk/timeline/test/registry.test.ts
index f4d3ee79..c1a38262 100644
--- a/sdk/timeline/test/registry.test.ts
+++ b/sdk/timeline/test/registry.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"
-import { CURVES, EASES, gridFrames, palette, readAdds, seqEdits, fromSequences, TEXTS, TRANSITIONS } from "../src"
+import { COMBOS, CURVES, EASES, gridFrames, palette, readAdds, seqEdits, fromSequences, TEXTS, TRANSITIONS } from "../src"
describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
const raw = {
@@ -33,7 +33,15 @@ describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
test("with no plugin it is raea's own, and a manifest with no timeline adds nothing", () => {
expect(palette().transitions).toEqual(TRANSITIONS)
expect(readAdds(undefined)).toEqual({ adds: {}, errors: [] })
- expect(readAdds([1]).errors).toEqual(["timeline is an object: { eases, curves, transitions, tracks, effects, texts, tools, snaps }"])
+ expect(readAdds([1]).errors).toEqual(["timeline is an object: { eases, curves, transitions, combos, tracks, effects, texts, tools, snaps }"])
+ })
+
+ test("TL7e: a plugin's Combos, each a wave of the props a clip moves by, checked", () => {
+ const wobble = { kind: "wobble", title: "Wobble", wave: { x: [0, 4, 0], rotate: [0, 2, 0] } }
+ const { adds, errors } = readAdds({ combos: [wobble, { kind: "pulse", title: "Mine", wave: { scale: [1, 2] } }, { kind: "bad", title: "Bad", wave: { skew: [1] } }, { kind: "empty", title: "Empty", wave: { x: [] } }] })
+ expect(adds.combos).toEqual([wobble])
+ expect(errors).toEqual(['timeline.combos[1]: raea has a combo "pulse"', "timeline.combos[2] (bad): a wave moves x, y, scale, rotate, opacity, not skew", "timeline.combos[3] (empty): wave.x is 1 to 64 numbers over one cycle"])
+ expect(palette([adds]).combos.map((c) => c.kind)).toEqual([...COMBOS.map((c) => c.kind), "wobble"])
})
})
diff --git a/sdk/video/src/edges.ts b/sdk/video/src/edges.ts
index 29f317c0..339c43ee 100644
--- a/sdk/video/src/edges.ts
+++ b/sdk/video/src/edges.ts
@@ -42,13 +42,90 @@ export function transitionStyle(kind: TransitionKind, side: "in" | "out", p: num
return { opacity: p };
}
+/** Styles drawn at once: the moves side by side in order, the fades multiplied, the first cover. */
+export function joinStyles(...styles: EdgeStyle[]): EdgeStyle {
+ const transform = styles.map((s) => s.transform).filter(Boolean).join(" ") || undefined;
+ const fades = styles.filter((s) => s.opacity !== undefined);
+ const opacity = fades.length ? fades.reduce((p, s) => p * Number(s.opacity), 1) : undefined;
+ const clipPath = styles.find((s) => s.clipPath)?.clipPath;
+ return { ...(transform ? { transform } : {}), ...(opacity !== undefined ? { opacity } : {}), ...(clipPath ? { clipPath } : {}) };
+}
+
/** A part's style at its own `frame` of `duration`, coming in by `enter` and going out by `exit`: both at once (a part
* shorter than its two edges) puts the moves side by side and multiplies the fades. Empty when neither plays. */
export function edgesStyle(enter: TransitionEdge | undefined, exit: TransitionEdge | undefined, frame: number, duration: number): EdgeStyle {
const a = enter ? transitionStyle(enter.kind, "in", transitionAt(enter, "in", frame, duration)) : {};
const b = exit ? transitionStyle(exit.kind, "out", transitionAt(exit, "out", frame, duration)) : {};
- const transform = [a.transform, b.transform].filter(Boolean).join(" ") || undefined;
- const opacity = a.opacity === undefined && b.opacity === undefined ? undefined : Number(a.opacity ?? 1) * Number(b.opacity ?? 1);
- const clipPath = a.clipPath ?? b.clipPath;
- return { ...(transform ? { transform } : {}), ...(opacity !== undefined ? { opacity } : {}), ...(clipPath ? { clipPath } : {}) };
+ return joinStyles(a, b);
+}
+
+/** How a part moves over one cycle of a Combo (CapCut's third kind of animation, docs/timeline.feature TL7e): each
+ * property's values, evenly spaced over the cycle and eased between, the cycle starting again where it ends. x and y
+ * move it by a share of its own size in percent, rotate turns it in degrees, scale sizes it, opacity fades it. A wave
+ * that ends where it starts plays once over the part as CapCut's Combo does, and loops seamlessly as its text Loop does. */
+export interface ComboWave {
+ /** across, in percent of its width */
+ x?: number[];
+ /** down, in percent of its height */
+ y?: number[];
+ /** its size, 1 as it is */
+ scale?: number[];
+ /** turned, in degrees */
+ rotate?: number[];
+ /** how much of it shows, 0 to 1 */
+ opacity?: number[];
+}
+
+/** A kind of Combo: its name, what the person sees, and its wave. */
+export interface ComboKind {
+ /** its name, as code writes it */
+ kind: string;
+ /** what the person sees */
+ title: string;
+ /** how it moves over one cycle */
+ wave: ComboWave;
+ /** straight from value to value, not eased: a spin that keeps turning */
+ linear?: boolean;
+}
+
+/** raea's own Combos: the kinds <Transition combo> draws. A plugin adds its own as data the same way. */
+export const COMBOS: ComboKind[] = [
+ { kind: "pulse", title: "Pulse", wave: { scale: [1, 1.08, 1] } },
+ { kind: "sway", title: "Sway", wave: { rotate: [0, 4, 0, -4, 0] } },
+ { kind: "float", title: "Float", wave: { y: [0, -3, 0] } },
+ { kind: "shake", title: "Shake", wave: { x: [0, 1.2, -1, 0.8, -1.2, 0], y: [0, -0.8, 1, -0.6, 0.5, 0] } },
+ { kind: "swing", title: "Swing", wave: { rotate: [0, 8, -6, 4, -2, 0], scale: [1, 1.04, 1, 1.02, 1, 1] } },
+ { kind: "spin", title: "Spin", wave: { rotate: [0, 360] }, linear: true },
+ { kind: "flicker", title: "Flicker", wave: { opacity: [1, 0.35, 1, 1, 0.55, 1] } },
+];
+export const COMBO_KINDS: string[] = COMBOS.map((c) => c.kind);
+
+/** A Combo as a part plays it: which kind, and how many frames one cycle takes (the part's length plays it once). */
+export interface ComboLoop {
+ /** which Combo: one of COMBO_KINDS */
+ kind: string;
+ /** the frames one cycle takes */
+ frames: number;
+}
+
+const three = (v: number) => Math.round(v * 1000) / 1000;
+
+/** A Combo's style at the part's own `frame`, a cycle every `frames`. */
+export function comboStyle(combo: ComboKind | undefined, frame: number, frames: number): EdgeStyle {
+ if (!combo || !(frames >= 1)) return {};
+ const p = (((frame % frames) + frames) % frames) / frames;
+ const at = (vs: number[] | undefined): number | undefined => {
+ if (!vs?.length) return undefined;
+ if (vs.length === 1) return vs[0];
+ const x = p * (vs.length - 1), n = Math.min(vs.length - 2, Math.floor(x)), f = x - n;
+ const e = combo.linear ? f : f * f * (3 - 2 * f);
+ return vs[n] + (vs[n + 1] - vs[n]) * e;
+ };
+ const w = combo.wave, x = at(w.x), y = at(w.y), r = at(w.rotate), s = at(w.scale), o = at(w.opacity);
+ const moves = [
+ x !== undefined || y !== undefined ? `translate(${three(x ?? 0)}%, ${three(y ?? 0)}%)` : "",
+ r !== undefined ? `rotate(${three(r)}deg)` : "",
+ s !== undefined ? `scale(${three(s)})` : "",
+ ].filter(Boolean);
+ return { ...(moves.length ? { transform: moves.join(" ") } : {}), ...(o !== undefined ? { opacity: three(Math.min(1, Math.max(0, o))) } : {}) };
}
diff --git a/sdk/video/src/transition.tsx b/sdk/video/src/transition.tsx
index f0959884..70b0afe9 100644
--- a/sdk/video/src/transition.tsx
+++ b/sdk/video/src/transition.tsx
@@ -5,29 +5,33 @@
// as long as it was. The kinds and their styles are edges.ts, which the timeline's preview draws with too.
import type { ReactNode } from "react";
import { useLocalTime } from "@raea/app/clock";
-import { edgesStyle, TRANSITION_KINDS, type TransitionEdge } from "./edges";
+import { COMBO_KINDS, COMBOS, type ComboLoop, comboStyle, edgesStyle, joinStyles, TRANSITION_KINDS, type TransitionEdge } from "./edges";
import { AbsoluteFill } from "./timeline";
-export { edgesStyle, type EdgeStyle, TRANSITION_KINDS, transitionAt, type TransitionEdge, type TransitionKind, transitionStyle } from "./edges";
+export { COMBO_KINDS, COMBOS, type ComboKind, type ComboLoop, comboStyle, type ComboWave, edgesStyle, type EdgeStyle, joinStyles, TRANSITION_KINDS, transitionAt, type TransitionEdge, type TransitionKind, transitionStyle } from "./edges";
export interface TransitionProps {
/** over the part's first frames */
in?: TransitionEdge;
/** over the part's last frames */
out?: TransitionEdge;
+ /** a Combo over the whole part (TL7e): a cycle every `frames`, from its first frame */
+ combo?: ComboLoop;
/** the part it brings in and takes out: what the <Sequence> holds */
children?: ReactNode;
}
-/** Its children, coming in over the part's first frames and going out over its last. */
-export function Transition({ in: enter, out: exit, children }: TransitionProps) {
+/** Its children, coming in over the part's first frames, going out over its last, and moving by a Combo throughout. */
+export function Transition({ in: enter, out: exit, combo, children }: TransitionProps) {
const t = useLocalTime("Transition");
for (const [side, edge] of [["in", enter], ["out", exit]] as const) {
if (!edge) continue;
if (!TRANSITION_KINDS.includes(edge.kind)) throw new RangeError(`Transition: ${side}.kind is one of ${TRANSITION_KINDS.join(", ")}, got ${String(edge.kind)}`);
if (!Number.isFinite(edge.frames) || edge.frames < 0) throw new RangeError(`Transition: ${side}.frames must be 0 or more, got ${edge.frames}`);
}
- const style = edgesStyle(enter, exit, t.frame, t.duration);
+ if (combo && !COMBO_KINDS.includes(combo.kind)) throw new RangeError(`Transition: combo.kind is one of ${COMBO_KINDS.join(", ")}, got ${String(combo.kind)}`);
+ if (combo && (!Number.isFinite(combo.frames) || combo.frames < 0)) throw new RangeError(`Transition: combo.frames must be 0 or more, got ${combo.frames}`);
+ const style = joinStyles(edgesStyle(enter, exit, t.frame, t.duration), combo ? comboStyle(COMBOS.find((c) => c.kind === combo.kind), t.frame, combo.frames) : {});
if (!style.transform && style.opacity === undefined && !style.clipPath) return <>{children}</>;
return <AbsoluteFill style={style}>{children}</AbsoluteFill>;
}