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.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
TL11a: a plugin's effects as data: <Effect parts> draws an effect from CSS filter functions (amount 0 to amount 1), the timeline's palette reads them from a plugin's manifest (timeline.effects) and its writer carries them to the composition
shinyobjectzf14232a52ee1
diff --git a/docs/manual/reference/sdk/index.md b/docs/manual/reference/sdk/index.mdindex 214a00d6..2873bb17 100644--- a/docs/manual/reference/sdk/index.md+++ b/docs/manual/reference/sdk/index.md@@ -31,7 +31,7 @@ The composition, the app, and the specs and notes an agent writes.| Import | What it's for | Exports || --- | --- | --- |-| [`raea`](raea.md) | The main entry: compositions, sequences, time, interpolation, springs, footage, sound and words. | 20 components, 8 hooks, 60 functions, 10 values, 97 types |+| [`raea`](raea.md) | The main entry: compositions, sequences, time, interpolation, springs, footage, sound and words. | 20 components, 8 hooks, 62 functions, 11 values, 98 types || [`raea/app`](app.md) | The App, its plugins and schedules, and the registry a video's compositions are kept in. | 1 component, 4 functions, 3 classes, 17 values, 8 types || [`raea/brief`](brief.md) | The specs an agent writes as data: brief, script, taste, plan and controller, checked against raea's schemas. | 6 functions, 32 types || [`raea/note`](note.md) | A person's note as a file in the project: their words kept as written, and the asks the agent restates it as. | 1 function, 4 types |diff --git a/docs/manual/reference/sdk/raea.md b/docs/manual/reference/sdk/raea.mdindex 5feba702..c54fc147 100644--- a/docs/manual/reference/sdk/raea.md+++ b/docs/manual/reference/sdk/raea.md@@ -38,7 +38,7 @@ See [Your first video](../../start/first-video.md) for the whole loop, andimport { AbsoluteFill, ACTION_KEY, actionsIn, Animate } from "raea"```-`raea` exports 20 components, 8 hooks, 60 functions, 10 values, 97 types. Source: [sdk/raea/src/index.tsx](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/index.tsx).+`raea` exports 20 components, 8 hooks, 62 functions, 11 values, 98 types. Source: [sdk/raea/src/index.tsx](https://github.com/shinyobjectz/raea/blob/main/sdk/raea/src/index.tsx).## Components@@ -116,7 +116,8 @@ The picture under it, through the effect, for as long as its <Sequence> runs.| Prop | Type | What it does || --- | --- | --- |-| `kind` (required) | `string` | which effect: blur, mono, sepia, vivid, faded, contrast, bright, dark, invert or hue |+| `kind` (required) | `string` | which effect: blur, mono, sepia, vivid, faded, contrast, bright, dark, invert or hue; with `parts`, its own name |+| `parts` | `EffectPart[]` | an effect of its own, as CSS filter functions (a plugin's): each [function, value at amount 0, value at amount 1, unit], such as [["blur", 0, 6, "px"], ["saturate", 1, 1.6]] || `amount` | `number` | how much of it, from 0 (none) to 1 (all, the default) || `in` | `number` | frames it takes to come on at its part's start (0: on at once) || `out` | `number` | frames it takes to go off by its part's end (0: off at once) |@@ -437,6 +438,14 @@ The CSS filter of `kind` at `amount` (0 to 1, clamped); undefined for a kind raefunction effectFilter(kind: string, amount?: number): string | undefined```+### `effectPartsError`++Why `parts` isn't an effect's parts, or undefined when it is.++```ts+function effectPartsError(parts: unknown): string | undefined+```+### `fade`opacity 0 to 1 over `frames` (6).@@ -585,6 +594,14 @@ Every step at once.function parallel(...steps: Step[]): Group```+### `partsFilter`++The CSS filter of an effect given as parts, at `amount` (0 to 1, clamped).++```ts+function partsFilter(parts: EffectPart[], amount?: number): string+```+### `pop`scale `from` (0.6), `peak` (1.08) at `frames`/2, 1 at `frames` (8); in over 3 frames.@@ -893,6 +910,10 @@ turn one round. Pass one as `interpolate`'s `easing`.Used in: [manual: turntable](https://github.com/shinyobjectz/raea/blob/main/docs/manual/examples/turntable.tsx).+### `EFFECT_FNS`++The filter functions a part may name, each with the units it takes.+### `EFFECTS`### `FEED_KEY`@@ -1148,6 +1169,15 @@ a split, a cut word or a moved span is a change to this list; the length becomes| `title` (required) | `string` | what the person sees || `filter` (required) | `(amount: number) => string` | the CSS filter at `amount` |+### `EffectPart`++An effect as data: each part one CSS filter function, its value going+from `from` (amount 0, where it changes nothing) to `to` (amount 1), with its unit: ["blur", 0, 6, "px"].++```ts+type EffectPart = [fn: string, from: number, to: number, unit?: string]+```+### `EffectProps`The props of [`Effect`](#effect), tabled there.diff --git a/docs/timeline.feature b/docs/timeline.featureindex 8d820456..d8419348 100644--- a/docs/timeline.feature+++ b/docs/timeline.feature@@ -78,15 +78,18 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in thesdk/video <Nudge keys>, <Transition in out> (fade, slide, wipe, zoom), <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 oran <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); 19 browser+ PR #19: the new timeline is the timeline (localStorage raea.timeline-sdk = 0 brings the old strip back); 20 browsertests in Chrome, 10 of them also passing in a headless raea window (the rest stop at helpers its runner lacks):built TL0a-d, TL1a-c (a plugin's lane as a row under the tracks; collapse and the top edge's resize),+ TL1d (the poster on the main track's head: a click makes the playhead's frame the poster),TL2a-e, TL3a-g, TL3h (freeze and reverse played live from the film's own frames; mirror,rotate and crop shown on the player at once, as are a clip's keyed scale, place, turn and opacity),TL3i, TL4a-c, TL5a-c, TL6a-b, TL7a, TL7b for raea's ten effects (an effect is a clip of its own,- shown on the player where it is on), TL7c (text added with T, renamed by a double-click), TL8a- (waveform, level line, fades), TL8b's beats as ticks that edges snap to (none can be turned off- yet), TL8c (Record from the playhead, the picture playing; the recording a clip named by what was+ shown on the player where it is on), TL7c (text added with T, renamed by a double-click, a caption split+ at the caret with Enter), 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), TL8b's beats as ticks that edges snap to, each turned off by a+ click, TL8c (Record from the playhead, the picture playing; the recording a clip named by what wassaid, its file in the project's attachments), TL11a for easings, speed curves, transitions and effects as data,TL9d (an item's own timeline: an edit kept in the item's data, Send telling its agent), TL12a-b,TL14a-c@@ -112,8 +115,7 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in thedecided TL10b, c and e in the SDK (which ranges an edit changes, a range's key, what goes first); acomposition's drafts are kept by their source, the least recently played going first under 1 GiB(RAEA_DRAFTS_LIMIT), so an undo plays its draft again at once- not built TL1d, effects and text a plugin- adds, a caption split with Enter, TL11a's tools and snapping targets, TL13 in a headless raea+ not built text styles a plugin adds, TL11a's tools and snapping targets, TL13 in a headless raeawindow (measured in Chrome so far, below). The skills guide's noteon an item's `timeline` field waits for PR #19 to mergediff --git a/sdk/guides/craft/motion/footage.md b/sdk/guides/craft/motion/footage.mdindex 868a8764..f1eede75 100644--- a/sdk/guides/craft/motion/footage.md+++ b/sdk/guides/craft/motion/footage.md@@ -36,6 +36,9 @@Kinds: `blur`, `mono` (black and white), `sepia`, `vivid`, `faded`, `contrast`, `bright`, `dark`, `invert`, `hue`.`amount` (0 to 1) says how much; `in` and `out` are the frames it takes to come on and go off. The feed's timelineshows such a sequence as an effect clip, so the person can move, trim or retune it there.+ An effect of your own is its `parts`, CSS filter functions from amount 0 to amount 1:+ `<Effect kind="dream" parts={[["blur", 0, 6, "px"], ["saturate", 1, 1.6]]} />` (blur, brightness, contrast,+ grayscale, hue-rotate, invert, saturate, sepia).- Use `<Img src>` for stills. The frame waits until the image has loaded. An image whose file isn't there fails therender with "missing image: PATH"; a plain App prints that line and draws nothing.diff --git a/sdk/raea/conformance/effect.test.tsx b/sdk/raea/conformance/effect.test.tsxindex accf225e..ca2dd666 100644--- a/sdk/raea/conformance/effect.test.tsx+++ b/sdk/raea/conformance/effect.test.tsx@@ -1,6 +1,6 @@// <Effect>: a look on the picture under it for its part's frames (docs/timeline.feature TL7b).import { expect, test } from "bun:test";-import { AbsoluteFill, Effect, EFFECTS, effectAt, effectFilter, Sequence } from "../src";+import { AbsoluteFill, Effect, EFFECTS, effectAt, effectFilter, effectPartsError, partsFilter, Sequence } from "../src";import { renderFrame } from "../src/test";const base = { frame: 0, fps: 30, width: 1080, height: 1920, durationInFrames: 90 };@@ -31,3 +31,14 @@ test("every kind gives a filter, none at amount 0 changes the picture's numbers,expect(() => at(40, <Effect kind="nope" />)).toThrow(/kind is one of/);expect(() => at(40, <Effect kind="blur" amount={2} />)).toThrow(/amount/);});++test("an effect of its own is its parts: CSS filter functions from amount 0 to amount 1", () => {+ const dream = [["blur", 0, 6, "px"], ["saturate", 1, 1.6]] as [string, number, number, string?][];+ expect(partsFilter(dream, 1)).toBe("blur(6px) saturate(1.6)");+ expect(partsFilter(dream, 0)).toBe("blur(0px) saturate(1)");+ expect(at(40, <Effect kind="dream" parts={dream} amount={0.5} />)).toContain("backdrop-filter:blur(3px) saturate(1.3)");+ expect(effectPartsError(dream)).toBeUndefined();+ expect(effectPartsError([["drop-shadow", 0, 1]])).toMatch(/function is one of/);+ expect(effectPartsError([["blur", 0, 6, "em"]])).toMatch(/blur takes px/);+ expect(() => at(40, <Effect kind="dream" parts={[["url", 0, 1]] as never} />)).toThrow(/function is one of/);+});diff --git a/sdk/raea/src/index.tsx b/sdk/raea/src/index.tsxindex 4e4795ef..63007bc4 100644--- a/sdk/raea/src/index.tsx+++ b/sdk/raea/src/index.tsx@@ -56,7 +56,7 @@ export {} from "@raea/video/registry";export { Effect, effectAt, type EffectProps } from "@raea/video/effect";-export { EFFECTS, effectFilter, type EffectKind } from "@raea/video/effects";+export { EFFECTS, EFFECT_FNS, effectFilter, effectPartsError, partsFilter, type EffectKind, type EffectPart } from "@raea/video/effects";export { Nudge, type NudgeProps } from "@raea/video/nudge";export { speedLength, speedPoints, speedSource, type SpeedPoint } from "@raea/video/speed";export { Transition, type TransitionProps, type TransitionEdge, type TransitionKind } from "@raea/video/transition";diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.tsindex 75134c2f..3cbb867f 100644--- a/sdk/timeline/src/read.ts+++ b/sdk/timeline/src/read.ts@@ -4,7 +4,19 @@// every operation is a code edit of its own (edits.ts).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 } from "./registry"+import { EFFECTS, type EffectPart } from "./registry"+import { effectPartsError } from "../../video/src/effects"++/** An effect clip's parts, kept in its props as JSON: read back when they are well formed. */+export function effectParts(v: unknown): EffectPart[] | undefined {+ if (typeof v !== "string") return undefined+ try {+ const parts = JSON.parse(v) as unknown+ return effectPartsError(parts) ? undefined : (parts as EffectPart[])+ } catch {+ return undefined+ }+}/** A <Sequence> as the host lists it: its place among the file's elements, its span in the composition's frames,* the lane it sits on (nested ones below their parent, overlapping ones apart), and why it can't be rewritten. */@@ -28,7 +40,7 @@ export interface SeqRow {/** the words it shows, when words are all it shows: a text clip, its words changed by renaming it (TL7c) */text?: string/** the effect it puts on the picture under it, when an <Effect> is all it holds: an effect clip (TL7b) */- effect?: { kind: string; amount: number }+ effect?: { kind: string; amount: number; /** a plugin's: the parts that draw it */ parts?: EffectPart[] }/** how it comes in and goes out: its <Transition>'s in and out (TL7a) */in?: { kind: string; frames: number }out?: { kind: string; frames: number }@@ -68,7 +80,7 @@ export type SeqEdit =/** words put on the picture from `at` for `frames`: a new sequence after the composition's last (TL7c) */| { op: "text"; at: number; frames: number; text: string }/** an effect put on the picture from `at` for `frames`: a new sequence holding an <Effect>, after the composition's last (TL7b) */- | { op: "effect"; at: number; frames: number; kind: string; amount: number }+ | { op: "effect"; at: number; frames: number; kind: string; amount: number; /** a plugin's effect: the parts that draw it */ parts?: EffectPart[] }/** a recording put on the timeline from `at` for `frames` (TL8b): a new sequence holding an <Audio> of the file */| { op: "voice"; at: number; frames: number; file: string }/** an effect clip's kind or amount */@@ -101,7 +113,7 @@ export function fromSequences(rows: SeqRow[], fps: number): Timeline {const media = rows.filter((r) => r.media)rows = rows.filter((r) => !r.media)const lanes = [...new Set(rows.map((r) => r.lane))].sort((a, b) => a - b)- const clipsOf = (lane: number): Clip[] => rows.filter((r) => r.lane === lane).sort((a, b) => a.from - b.from).map((r) => ({ id: seqId(r.i), kind: r.effect ? "effect" : r.text === undefined ? "sequence" : "text", name: r.effect ? (EFFECTS.find((e) => e.kind === r.effect!.kind)?.title ?? r.effect.kind) : (r.text ?? r.label ?? r.name), ...(r.effect && { props: { effect: r.effect.kind, amount: r.effect.amount } }), ...(r.look && Object.keys(r.look).length && { props: lookProps(r.look) }), start: r.from, length: Math.max(1, r.to - r.from), ...(r.locked && { locked: r.locked }), ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.curve?.length && r.shows && { curve: r.curve.map(([at, speed]) => ({ at, speed })), shows: r.shows }), ...(r.keys && Object.keys(r.keys).length && { keys: Object.fromEntries(Object.entries(r.keys).map(([p, ks]) => [p, ks.map(([at, value, ease]): Key => ({ at, value, ...(ease !== undefined && { ease }) }))])) }) }))+ const clipsOf = (lane: number): Clip[] => rows.filter((r) => r.lane === lane).sort((a, b) => a.from - b.from).map((r) => ({ id: seqId(r.i), kind: r.effect ? "effect" : r.text === undefined ? "sequence" : "text", name: r.effect ? (EFFECTS.find((e) => e.kind === r.effect!.kind)?.title ?? r.effect.kind) : (r.text ?? r.label ?? r.name), ...(r.effect && { props: { effect: r.effect.kind, amount: r.effect.amount, ...(r.effect.parts && { parts: JSON.stringify(r.effect.parts) }) } }), ...(r.look && Object.keys(r.look).length && { props: lookProps(r.look) }), start: r.from, length: Math.max(1, r.to - r.from), ...(r.locked && { locked: r.locked }), ...(r.speed && r.speed !== 1 && { speed: r.speed }), ...(r.curve?.length && r.shows && { curve: r.curve.map(([at, speed]) => ({ at, speed })), shows: r.shows }), ...(r.keys && Object.keys(r.keys).length && { keys: Object.fromEntries(Object.entries(r.keys).map(([p, ks]) => [p, ks.map(([at, value, ease]): Key => ({ at, value, ...(ease !== undefined && { ease }) }))])) }) }))const first = lanes.length ? clipsOf(lanes[0]) : []const gapless = first.length > 0 && first.every((c, n) => c.start === (n ? end(first[n - 1]) : 0))const tracks: Track[] = lanes.map((lane, n) => ({ id: n === 0 && gapless ? "main" : `overlay-${lane}`, kind: n === 0 && gapless ? "main" : "overlay", clips: clipsOf(lane) }))@@ -214,9 +226,9 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {const only = Object.keys(op.set).filter((k) => op.set[k as keyof typeof op.set] !== undefined)// an effect clip's kind and amount are its <Effect>'sif (only.length === 1 && only[0] === "props" && find(t, op.id)?.clip.kind === "effect") {- const { effect, amount, ...other } = op.set.props!+ const { effect, amount, parts: _parts, ...other } = op.set.props!if (Object.keys(other).length) return { why: `an effect has a kind and an amount, not ${Object.keys(other).join(", ")}` }- if (effect !== undefined && !EFFECTS.some((e) => e.kind === effect)) return { why: `raea draws ${EFFECTS.map((e) => e.kind).join(", ")}: "${String(effect)}" isn't one of them` }+ if (effect !== undefined && !EFFECTS.some((e) => e.kind === effect)) return { why: `an effect clip changes to one of raea's own here (a plugin's is added from the bar): raea draws ${EFFECTS.map((e) => e.kind).join(", ")}: "${String(effect)}" isn't one of them` }if (amount !== undefined && !(typeof amount === "number" && amount >= 0 && amount <= 1)) return { why: "an effect's amount runs from 0 to 1" }return each([op.id], (r) => ({ op: "fx", i: r.i, ...(effect !== undefined && { kind: String(effect) }), ...(amount !== undefined && { amount: Math.round((amount as number) * 1000) / 1000 }) }))}@@ -269,9 +281,12 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {// an effect put on the picture: a new sequence of its own, holding an <Effect>if (op.clip.kind === "effect") {const kind = String(op.clip.props?.effect ?? "")- if (!EFFECTS.some((e) => e.kind === kind)) return { why: `raea draws ${EFFECTS.map((e) => e.kind).join(", ")}: "${kind}" isn't one of them` }+ // a plugin's effect carries the parts that draw it (as its clip does, in JSON)+ const parts = effectParts(op.clip.props?.parts)+ if (!parts && !EFFECTS.some((e) => e.kind === kind)) return { why: `raea draws ${EFFECTS.map((e) => e.kind).join(", ")}: "${kind}" isn't one of them` }+ if (!/^[a-z][a-z0-9-]*$/.test(kind)) return { why: "an effect's kind is a name in lowercase letters, digits and dashes" }const amount = typeof op.clip.props?.amount === "number" ? Math.min(1, Math.max(0, op.clip.props.amount)) : 1- return [{ op: "effect", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), kind, amount }]+ return [{ op: "effect", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), kind, amount, ...(parts && { parts }) }]}// a recording made here (its file on this Mac): a new sequence of its own, holding an <Audio>if (op.clip.kind === "audio" && typeof op.clip.props?.file === "string" && op.clip.props.file) return [{ op: "voice", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), file: op.clip.props.file }]diff --git a/sdk/timeline/src/registry.ts b/sdk/timeline/src/registry.tsindex d493def0..be15a16a 100644--- a/sdk/timeline/src/registry.ts+++ b/sdk/timeline/src/registry.ts@@ -5,9 +5,16 @@ import { EASES } from "./keys"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 } from "../../video/src/effects"+import { EFFECTS, effectFilter, type EffectKind, type EffectPart, effectPartsError, partsFilter } from "../../video/src/effects"-export { EFFECTS, effectFilter, type EffectKind }+export { EFFECTS, effectFilter, type EffectKind, type EffectPart, partsFilter }++/** An effect the palette offers: raea's own by its kind, a plugin's with the parts that draw it. */+export interface EffectInfo {+ kind: string+ title: string+ parts?: EffectPart[]+}export interface TransitionKind {/** the component's name in the composition's code */@@ -30,6 +37,8 @@ export interface Adds {transitions?: TransitionKind[]/** 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 */+ effects?: EffectInfo[]}/** raea's own kinds of track, in the order they stack (TL1a). */@@ -59,7 +68,7 @@ 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 }"] }+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return { adds, errors: ["timeline is an object: { eases, curves, transitions, tracks, effects }"] }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")) {@@ -92,21 +101,35 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {else (adds.tracks ??= []).push({ kind: t.kind, title: t.title, ...(t.under === true && { under: true }) })}}+ if (r.effects !== undefined) {+ if (!Array.isArray(r.effects)) errors.push("timeline.effects is a list of { kind, title, parts }")+ else+ for (const [i, x] of r.effects.entries()) {+ const e = x as Partial<EffectInfo> | null+ const why = e ? effectPartsError(e.parts) : undefined+ if (!e || typeof e.kind !== "string" || !/^[a-z][a-z0-9-]*$/.test(e.kind) || typeof e.title !== "string" || !e.title.trim()) errors.push(`timeline.effects[${i}] is { kind, title, parts }: kind in lowercase letters, digits and dashes, title what the person sees`)+ else if (EFFECTS.some((o) => o.kind === e.kind)) errors.push(`timeline.effects[${i}]: raea has an effect "${e.kind}"`)+ else if (why) errors.push(`timeline.effects[${i}] (${e.kind}): ${why}`)+ else (adds.effects ??= []).push({ kind: e.kind, title: e.title, parts: e.parts! })+ }+ }return { adds, errors }}/** 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: { kind: string; title: string }[] } {+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[] } {const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS], tracks = [...TRACKS]+ const effects: EffectInfo[] = EFFECTS.map(({ kind, title }) => ({ kind, title }))for (const p of plugins) {for (const [n, e] of Object.entries(p.eases ?? {})) if (!(n in eases)) eases[n] = efor (const [n, c] of Object.entries(p.curves ?? {})) if (!(n in curves)) curves[n] = cfor (const t of p.transitions ?? []) if (!transitions.some((o) => o.kind === t.kind)) transitions.push(t)+ for (const e of p.effects ?? []) if (!effects.some((o) => o.kind === e.kind)) effects.push(e)for (const t of p.tracks ?? [])if (!tracks.some((o) => o.kind === t.kind)) {tracks.push(t)if (t.under) under.add(t.kind)}}- return { eases, curves, transitions, tracks, effects: EFFECTS.map(({ kind, title }) => ({ kind, title })) }+ return { eases, curves, transitions, tracks, effects }}diff --git a/sdk/timeline/test/read.test.ts b/sdk/timeline/test/read.test.tsindex 0cf3c16d..b4661f1c 100644--- a/sdk/timeline/test/read.test.ts+++ b/sdk/timeline/test/read.test.ts@@ -86,6 +86,11 @@ describe("TL0c: a timeline is read from a composition", () => {expect(seqEdits(t, { op: "add", kind: "effect", clip: { id: "new", kind: "effect", props: { effect: "sparkle" }, start: 30, length: 60 } })).toMatchObject({ why: expect.stringContaining('"sparkle" isn\'t one of them') })// moved and trimmed like any sequenceexpect(seqEdits(t, { op: "move", ids: ["seq-1"], by: 10 })).toEqual([{ op: "move", i: 1, from: 25, to: 70 }])+ // a plugin's effect goes with the parts that draw it, and is read back with them+ const parts = [["blur", 0, 6, "px"], ["saturate", 1, 1.6]]+ expect(seqEdits(t, { op: "add", kind: "effect", clip: { id: "new", kind: "effect", name: "Dream", props: { effect: "dream", amount: 1, parts: JSON.stringify(parts) }, start: 0, length: 30 } })).toEqual([{ op: "effect", at: 0, frames: 30, kind: "dream", amount: 1, parts }])+ const back = fromSequences([{ ...rows[2], effect: { kind: "dream", amount: 0.5, parts: parts as never } }], 30).tracks[0].clips[0]+ expect([back.name, back.props]).toEqual(["dream", { effect: "dream", amount: 0.5, parts: JSON.stringify(parts) }])})test("a <Video> and an <Audio> are clips of their own under their sequence: their level is theirs, the rest the sequence's", () => {diff --git a/sdk/timeline/test/registry.test.ts b/sdk/timeline/test/registry.test.tsindex 23ba37c1..bf1e71ea 100644--- a/sdk/timeline/test/registry.test.ts+++ b/sdk/timeline/test/registry.test.ts@@ -33,6 +33,28 @@ 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 }"])+ expect(readAdds([1]).errors).toEqual(["timeline is an object: { eases, curves, transitions, tracks, effects }"])+ })+})++describe("TL11a: a plugin's effects", () => {+ test("are data: CSS filter functions from amount 0 to amount 1, checked, and offered after raea's own", () => {+ const { adds, errors } = readAdds({+ effects: [+ { kind: "dream", title: "Dream", parts: [["blur", 0, 6, "px"], ["saturate", 1, 1.6]] },+ { kind: "blur", title: "Mine", parts: [["blur", 0, 2, "px"]] },+ { kind: "shadow", title: "Shadow", parts: [["drop-shadow", 0, 1]] },+ { kind: "Bad Name", title: "x", parts: [["blur", 0, 2, "px"]] },+ ],+ })+ expect(adds.effects).toEqual([{ kind: "dream", title: "Dream", parts: [["blur", 0, 6, "px"], ["saturate", 1, 1.6]] }])+ expect(errors).toEqual([+ 'timeline.effects[1]: raea has an effect "blur"',+ expect.stringContaining("timeline.effects[2] (shadow): a part's function is one of"),+ "timeline.effects[3] is { kind, title, parts }: kind in lowercase letters, digits and dashes, title what the person sees",+ ])+ const all = palette([adds]).effects+ expect(all[all.length - 1]).toEqual(adds.effects![0])+ expect(all.length).toBe(11)})})diff --git a/sdk/video/src/effect.tsx b/sdk/video/src/effect.tsxindex 1301b43e..9403621e 100644--- a/sdk/video/src/effect.tsx+++ b/sdk/video/src/effect.tsx@@ -3,11 +3,14 @@// moved, trimmed, split and deleted like any other clip. It draws nothing itself: it filters what is behind it.import { useLocalTime } from "@raea/app/clock";import { AbsoluteFill } from "./timeline";-import { EFFECTS, effectFilter } from "./effects";+import { EFFECTS, effectFilter, effectPartsError, partsFilter, type EffectPart } from "./effects";export interface EffectProps {- /** which effect: blur, mono, sepia, vivid, faded, contrast, bright, dark, invert or hue */+ /** which effect: blur, mono, sepia, vivid, faded, contrast, bright, dark, invert or hue; with `parts`, its own name */kind: string;+ /** an effect of its own, as CSS filter functions (a plugin's): each [function, value at amount 0, value at+ * amount 1, unit], such as [["blur", 0, 6, "px"], ["saturate", 1, 1.6]] */+ parts?: EffectPart[];/** how much of it, from 0 (none) to 1 (all, the default) */amount?: number;/** frames it takes to come on at its part's start (0: on at once) */@@ -24,11 +27,15 @@ export function effectAt(frame: number, duration: number, enter = 0, exit = 0):}/** The picture under it, through the effect, for as long as its <Sequence> runs. */-export function Effect({ kind, amount = 1, in: enter = 0, out: exit = 0 }: EffectProps) {+export function Effect({ kind, parts, amount = 1, in: enter = 0, out: exit = 0 }: EffectProps) {const t = useLocalTime("Effect");- if (!EFFECTS.some((e) => e.kind === kind)) throw new RangeError(`Effect: kind is one of ${EFFECTS.map((e) => e.kind).join(", ")}, got ${String(kind)}`);+ if (parts !== undefined) {+ const why = effectPartsError(parts);+ if (why) throw new RangeError(`Effect ${kind}: ${why}`);+ } else if (!EFFECTS.some((e) => e.kind === kind)) throw new RangeError(`Effect: kind is one of ${EFFECTS.map((e) => e.kind).join(", ")} (or give its parts), got ${String(kind)}`);if (!Number.isFinite(amount) || amount < 0 || amount > 1) throw new RangeError(`Effect ${kind}: amount runs from 0 to 1, got ${amount}`);for (const [name, v] of [["in", enter], ["out", exit]] as const) if (!Number.isFinite(v) || v < 0) throw new RangeError(`Effect ${kind}: ${name} must be 0 or more frames, got ${v}`);- const filter = effectFilter(kind, amount * effectAt(t.frame, t.duration, enter, exit));+ const on = amount * effectAt(t.frame, t.duration, enter, exit);+ const filter = parts ? partsFilter(parts, on) : effectFilter(kind, on);return <AbsoluteFill data-effect={kind} style={{ backdropFilter: filter, pointerEvents: "none" }} />;}diff --git a/sdk/video/src/effects.ts b/sdk/video/src/effects.tsindex d1ac7e71..f422984a 100644--- a/sdk/video/src/effects.ts+++ b/sdk/video/src/effects.ts@@ -25,6 +25,39 @@ export const EFFECTS: EffectKind[] = [{ kind: "hue", title: "Hue shift", filter: (a) => `hue-rotate(${n(a * 180)}deg)` },];+/** An effect as data (a plugin's, docs/timeline.feature TL11a): each part one CSS filter function, its value going+ * from `from` (amount 0, where it changes nothing) to `to` (amount 1), with its unit: ["blur", 0, 6, "px"]. */+export type EffectPart = [fn: string, from: number, to: number, unit?: string];++/** The filter functions a part may name, each with the units it takes. */+export const EFFECT_FNS: Record<string, string[]> = {+ blur: ["px"],+ brightness: [""],+ contrast: [""],+ grayscale: [""],+ "hue-rotate": ["deg"],+ invert: [""],+ saturate: [""],+ sepia: [""],+};++/** Why `parts` isn't an effect's parts, or undefined when it is. */+export function effectPartsError(parts: unknown): string | undefined {+ if (!Array.isArray(parts) || !parts.length || parts.length > 8) return "parts is one to eight [function, from, to, unit] entries";+ for (const p of parts) {+ if (!Array.isArray(p) || typeof p[0] !== "string" || !(p[0] in EFFECT_FNS)) return `a part's function is one of ${Object.keys(EFFECT_FNS).join(", ")}`;+ if (typeof p[1] !== "number" || typeof p[2] !== "number" || !Number.isFinite(p[1]) || !Number.isFinite(p[2])) return `${p[0]}: from and to are numbers`;+ if (!EFFECT_FNS[p[0]].includes(p[3] ?? "")) return `${p[0]} takes ${EFFECT_FNS[p[0]].map((u) => u || "no unit").join(" or ")}`;+ }+ return undefined;+}++/** The CSS filter of an effect given as parts, at `amount` (0 to 1, clamped). */+export function partsFilter(parts: EffectPart[], amount = 1): string {+ const a = Math.min(1, Math.max(0, amount));+ return parts.map(([fn, from, to, unit = ""]) => `${fn}(${n(from + (to - from) * a)}${unit})`).join(" ");+}+/** The CSS filter of `kind` at `amount` (0 to 1, clamped); undefined for a kind raea doesn't draw. */export function effectFilter(kind: string, amount = 1): string | undefined {const e = EFFECTS.find((x) => x.kind === kind);