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.

TL7c, TL11a: text styles as data in the timeline SDK (raea's four, a plugin's checked), carried by the writer; the spec's status with the 3D scene's frame store seen through an edit in a raea window

shinyobjectz95725896a2b2
diff --git a/docs/timeline.feature b/docs/timeline.feature
index 11bfbafd..e373b9e9 100644
--- a/docs/timeline.feature
+++ b/docs/timeline.feature
@@ -78,7 +78,7 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
sdk/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 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); 20 browser
+ PR #19: the new timeline is the timeline (localStorage raea.timeline-sdk = 0 brings the old strip back); 21 browser
tests in Chrome; of the 19 that can run in a headless raea window (all but the voice test, which there would ask
for this Mac's microphone) 16 pass, among them a composition's every edit, freeze and reverse, mirror and crop,
effects, groups and compounds; the other three stop at the runner (a route answered late, a reload, a posted item):
@@ -87,8 +87,9 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
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, a caption split
- at the caret with Enter), a plugin's effects as data (timeline.effects in its manifest: parts
+ shown on the player where it is on), TL7c (text added with T or in a style from the bar, drawn over a
+ film where it is on, renamed by a double-click, a caption split at the caret with Enter; raea's
+ four text styles and a plugin's, as data), 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 was
@@ -112,12 +113,14 @@ Feature: The timeline SDK (0.1.5): CapCut's timeline, on the composition, in the
again only the ranges it is on and an undo plays what it had; the store stays under a size
(RAEA_SCENE_FRAMES_LIMIT, 1 GiB), the least recently played going first; the scene's timeline
shows what is kept, and Play runs it over the stage from the scene's own camera, handing back to
- the live stage where nothing is kept (seen in a headless raea window on the real host: the sample
- room drawn, kept, and played at its own rate)
+ the live stage where nothing is kept. Seen in a headless raea window on the real host: the sample
+ room drawn, kept, and played at its own rate; a 9 s copy of it opened again with every range
+ kept at once (0.5 s); and a sequence dragged across two of its three ranges drew those two again
+ (9.4 s) and left every kept file as it was
decided TL10b, c and e in the SDK (which ranges an edit changes, a range's key, what goes first); a
composition'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 text styles a plugin adds, TL11a's tools and snapping targets, TL13 in a headless raea
+ not built TL11a's tools and snapping targets, TL13 in a headless raea
window (measured in Chrome so far, below). The skills guide's note
on an item's `timeline` field waits for PR #19 to merge
diff --git a/sdk/timeline/src/read.ts b/sdk/timeline/src/read.ts
index 3cbb867f..799e953f 100644
--- a/sdk/timeline/src/read.ts
+++ b/sdk/timeline/src/read.ts
@@ -4,7 +4,18 @@
// 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, type EffectPart } from "./registry"
+import { EFFECTS, type EffectPart, type TextStyle, textStyleError } from "./registry"
+
+/** 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 {
+ if (typeof v !== "string") return undefined
+ try {
+ const t = JSON.parse(v) as unknown
+ return textStyleError(t) ? undefined : (t as TextStyle)
+ } catch {
+ return undefined
+ }
+}
import { effectPartsError } from "../../video/src/effects"
/** An effect clip's parts, kept in its props as JSON: read back when they are well formed. */
@@ -78,7 +89,7 @@ export type SeqEdit =
/** a text sequence's words (TL7c) */
| { op: "words"; i: number; text: string }
/** 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 }
+ | { op: "text"; at: number; frames: number; text: string; /** how the words are drawn: a text style (registry.ts), raea's title when none */ style?: TextStyle }
/** 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; /** 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 */
@@ -292,7 +303,8 @@ export function seqEdits(t: Timeline, op: Op): SeqEdit[] | { why: string } {
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 }]
// words put on the picture: a new sequence of its own
if (op.clip.kind !== "text") return { why: "only words, effects and recordings are added to a composition here: footage and sound are its code's to place" }
- return [{ op: "text", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), text: (op.clip.name ?? "Text").trim() || "Text" }]
+ const style = textStyleOf(op.clip.props?.style)
+ return [{ op: "text", at: Math.max(0, Math.round(op.clip.start)), frames: Math.max(1, Math.round(op.clip.length)), text: (op.clip.name ?? "Text").trim() || "Text", ...(style && { style }) }]
}
default:
return { why: `the composition's sequences don't take "${op.op}" yet` }
diff --git a/sdk/timeline/src/registry.ts b/sdk/timeline/src/registry.ts
index be15a16a..fd3f55e1 100644
--- a/sdk/timeline/src/registry.ts
+++ b/sdk/timeline/src/registry.ts
@@ -30,6 +30,35 @@ export interface TrackKindInfo {
under?: boolean
}
+/** A way words are put on the picture (TL7c): where they stand, and how they are drawn (CSS, as React writes it). */
+export interface TextStyle {
+ kind: string
+ title: string
+ place: "top" | "center" | "bottom"
+ style: Record<string, string | number>
+}
+/** The CSS a text style may set: type and colour, nothing that lays the frame out. */
+export const TEXT_PROPS = ["color", "fontSize", "fontWeight", "fontFamily", "fontStyle", "letterSpacing", "lineHeight", "textTransform", "textShadow", "background", "padding", "borderRadius", "opacity"]
+/** raea's own text styles. Sizes are the composition's pixels (a 1080-line frame). */
+export const TEXTS: TextStyle[] = [
+ { kind: "title", title: "Title", place: "bottom", style: { color: "white", fontSize: 72, fontWeight: 700, textShadow: "0 2px 16px rgba(0, 0, 0, 0.6)" } },
+ { kind: "headline", title: "Headline", place: "center", style: { color: "white", fontSize: 120, fontWeight: 800, letterSpacing: "-0.02em", textShadow: "0 4px 24px rgba(0, 0, 0, 0.5)" } },
+ { kind: "caption", title: "Caption", place: "bottom", style: { color: "white", fontSize: 44, fontWeight: 600, background: "rgba(0, 0, 0, 0.6)", padding: "8px 18px", borderRadius: 10 } },
+ { kind: "label", title: "Label", place: "top", style: { color: "white", fontSize: 36, fontWeight: 600, letterSpacing: "0.08em", textTransform: "uppercase", textShadow: "0 2px 10px rgba(0, 0, 0, 0.6)" } },
+]
+/** Why `t` isn't a text style, or undefined when it is. */
+export function textStyleError(t: unknown): string | undefined {
+ const x = t as Partial<TextStyle> | null
+ if (!x || typeof x.kind !== "string" || !/^[a-z][a-z0-9-]*$/.test(x.kind) || typeof x.title !== "string" || !x.title.trim()) return "is { kind, title, place, style }: kind in lowercase letters, digits and dashes, title what the person sees"
+ if (x.place !== "top" && x.place !== "center" && x.place !== "bottom") return "place is top, center or bottom"
+ if (!x.style || typeof x.style !== "object" || Array.isArray(x.style)) return "style is an object of CSS properties"
+ for (const [k, v] of Object.entries(x.style)) {
+ if (!TEXT_PROPS.includes(k)) return `style.${k}: a text style sets ${TEXT_PROPS.join(", ")}`
+ if (!(typeof v === "number" ? Number.isFinite(v) : typeof v === "string" && v.length <= 120 && !/[{}<>;]|url\(|expression/i.test(v))) return `style.${k} is a number or a plain CSS value`
+ }
+ return undefined
+}
+
/** What one plugin adds. */
export interface Adds {
eases?: Record<string, Ease>
@@ -39,6 +68,8 @@ export interface Adds {
tracks?: TrackKindInfo[]
/** effects of its own (TL7b, TL11a), each drawn by its parts: CSS filter functions from amount 0 to amount 1 */
effects?: EffectInfo[]
+ /** text styles of its own (TL7c, TL11a) */
+ texts?: TextStyle[]
}
/** raea's own kinds of track, in the order they stack (TL1a). */
@@ -113,23 +144,35 @@ export function readAdds(raw: unknown): { adds: Adds; errors: string[] } {
else (adds.effects ??= []).push({ kind: e.kind, title: e.title, parts: e.parts! })
}
}
+ if (r.texts !== undefined) {
+ if (!Array.isArray(r.texts)) errors.push("timeline.texts is a list of { kind, title, place, style }")
+ else
+ for (const [i, x] of r.texts.entries()) {
+ const why = textStyleError(x)
+ if (why) errors.push(`timeline.texts[${i}] ${why}`)
+ else if (TEXTS.some((o) => o.kind === (x as TextStyle).kind)) errors.push(`timeline.texts[${i}]: raea has a text style "${(x as TextStyle).kind}"`)
+ else (adds.texts ??= []).push(x as TextStyle)
+ }
+ }
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: EffectInfo[] } {
+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[] } {
const eases = { ...EASES }, curves = { ...CURVES }, transitions = [...TRANSITIONS], tracks = [...TRACKS]
const effects: EffectInfo[] = EFFECTS.map(({ kind, title }) => ({ kind, title }))
+ const texts = [...TEXTS]
for (const p of plugins) {
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 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 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 }
+ return { eases, curves, transitions, tracks, effects, texts }
}
diff --git a/sdk/timeline/test/registry.test.ts b/sdk/timeline/test/registry.test.ts
index bf1e71ea..74d4f71e 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, palette, readAdds, TRANSITIONS } from "../src"
+import { CURVES, EASES, palette, readAdds, seqEdits, fromSequences, TEXTS, TRANSITIONS } from "../src"
describe("TL11a: a plugin adds easings, speed curves and transitions", () => {
const raw = {
@@ -58,3 +58,16 @@ describe("TL11a: a plugin's effects", () => {
expect(all.length).toBe(11)
})
})
+
+describe("TL7c, TL11a: text styles", () => {
+ test("raea's own, and a plugin's checked: type and colour only, nothing that reads as code", () => {
+ const neon = { kind: "neon", title: "Neon", place: "center", style: { color: "#39ff14", fontSize: 96, textShadow: "0 0 24px #39ff14" } }
+ const { adds, errors } = readAdds({ texts: [neon, { ...neon, kind: "title" }, { ...neon, kind: "wide", style: { width: "100%" } }, { ...neon, kind: "sly", style: { background: "url(http://x)" } }, { ...neon, kind: "low", place: "left" }] })
+ expect(adds.texts).toEqual([neon])
+ expect(errors).toEqual(['timeline.texts[1]: raea has a text style "title"', expect.stringContaining("timeline.texts[2] style.width: a text style sets"), "timeline.texts[3] style.background is a number or a plain CSS value", "timeline.texts[4] place is top, center or bottom"])
+ expect(palette([adds]).texts.map((t) => t.kind)).toEqual([...TEXTS.map((t) => t.kind), "neon"])
+ // added to a composition, the words go with their style
+ const t = fromSequences([{ i: 0, name: "Sequence", label: "A", from: 0, to: 90, lane: 0 }], 30)
+ expect(seqEdits(t, { op: "add", kind: "text", clip: { id: "text-1", kind: "text", name: "Hi", props: { style: JSON.stringify(neon) }, start: 0, length: 60 } })).toEqual([{ op: "text", at: 0, frames: 60, text: "Hi", style: neon }])
+ })
+})