The VS Code of video editing, built for agents.
TypeScript
Enhance Animation Documentation and Logic
konstantin-paulusf00276fd8662
diff --git a/docs/reference/jsx/animations.md b/docs/reference/jsx/animations.mdindex 14553eda..3a9da59c 100644--- a/docs/reference/jsx/animations.md+++ b/docs/reference/jsx/animations.md@@ -24,13 +24,13 @@ The editor's animations inspector options:| `type` | Effect || ------ | ------ |-| `"fade"` | Opacity ramp. |+| `"fade"` | Opacity ramp between 0 and the node's opacity. || `"slideLeft"`, `"slideRight"`, `"slideUp"`, `"slideDown"` | Slide in from (or out toward) the named direction, fading. |-| `"grow"` | Scales up from 50%. |-| `"shrink"` | Scales down from 150%. |+| `"grow"` | Scales up from 50% of the node's scale. |+| `"shrink"` | Scales down from 150% of the node's scale. || `"spin"` | Scale plus rotation. || `"twist"` | Overscale plus rotation and offset. |-| `"blur"` | 24px blur ramp. |+| `"blur"` | 24px blur ramp on top of the node's blur. || `"appearWord"` | Text only: reveals the text word by word. || `"appearChar"` | Text only: reveals the text character by character. || `"scramble"` | Text only: resolves scrambled characters into the text. |@@ -41,4 +41,5 @@ Text types apply only to [`<text>`](./text.md) and [`<captions>`](./captions.md)## Semantics- `duration` and `delay` take any [time format](./timing.md#time-formats). An `"in"` animation plays over `[delay, delay + duration]` from the clip's in point; an `"out"` animation ends `delay` before the clip's out point. Both track the clip when it is retimed.-- A node takes **any number of animations**; overlapping ones apply in document order, later ones writing over earlier ones on the properties they share. A [keyframe track](./keyframes.md) on the same property (say, a keyframed `opacity` next to `"fade"`) overrides the preset while it has keyframes; presets and keyframes on distinct properties compose freely.+- Presets are **relative to the node's authored props**: they scale or shift them rather than replace them. A `"fade"` on a clip with `opacity={0.8}` ramps between 0 and 0.8, `"grow"` on a clip with `scale={2}` grows from 1 to 2, and slides move from the authored `offsetX`/`offsetY`.+- A node takes **any number of animations**; overlapping ones compound on the properties they share (a `"fade"` and a `"slideUp"` running together multiply their opacity ramps). The text types are the exception: they replace the displayed text, so the later one in document order wins. A [keyframe track](./keyframes.md) on the same property (say, a keyframed `opacity` next to `"fade"`) overrides the preset while it has keyframes; presets and keyframes on distinct properties compose freely.diff --git a/packages/runtime/src/systems/motion.ts b/packages/runtime/src/systems/motion.tsindex 73c69624..568cf9d9 100644--- a/packages/runtime/src/systems/motion.ts+++ b/packages/runtime/src/systems/motion.ts@@ -72,6 +72,9 @@ export function resetAnimatedValues(world: World, entity: Entity | null, ignore?/*** Apply a preset animation to a node at the given normalized progress.+ * Presets scale or shift the Computed values in place, which start each+ * frame at the authored values, so a fade-in on a clip at 80% opacity lands+ * on 80%, and overlapping presets on a shared property compound.*/function applyAnimation(world: World, entity: Entity, anim: Entity, progress: number) {const computed = store(world, Computed);@@ -85,7 +88,7 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nuconst phase = animation.phase[aid];const func = cubicBezier(0.1, 0.7, 0.5, 1);const eased = clamp01(func(progress));- computed.opacity[eid] = phase === AnimationPhase.OUT ? 1 - eased : eased;+ computed.opacity[eid]! *= phase === AnimationPhase.OUT ? 1 - eased : eased;break;}case AnimationType.GAIN: {@@ -102,8 +105,8 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nuconst eased = clamp01(func(progress));const t = phase === AnimationPhase.OUT ? eased : 1 - eased;const scale = 1 - 0.5 * t;- computed.scaleX[eid] = scale;- computed.scaleY[eid] = scale;+ computed.scaleX[eid]! *= scale;+ computed.scaleY[eid]! *= scale;break;}case AnimationType.SHRINK: {@@ -112,15 +115,15 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nuconst eased = clamp01(func(progress));const t = phase === AnimationPhase.OUT ? eased : 1 - eased;const scale = 1 + 0.5 * t;- computed.scaleX[eid] = scale;- computed.scaleY[eid] = scale;+ computed.scaleX[eid]! *= scale;+ computed.scaleY[eid]! *= scale;break;}case AnimationType.BLUR: {const phase = animation.phase[aid];const func = phase === AnimationPhase.OUT ? cubicBezier(0.4, 0, 1, 1) : cubicBezier(0.33, 0, 0.2, 1);const eased = clamp01(func(progress));- computed.blur[eid] = phase === AnimationPhase.OUT ? lerp(0, 24, eased) : lerp(24, 0, eased);+ computed.blur[eid]! += phase === AnimationPhase.OUT ? lerp(0, 24, eased) : lerp(24, 0, eased);break;}case AnimationType.SLIDE_LEFT:@@ -135,15 +138,15 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nuconst sign = phase === AnimationPhase.OUT ? -1 : 1;if (type === AnimationType.SLIDE_LEFT) {- computed.offsetX[eid] = sign * 100 * t;+ computed.offsetX[eid]! += sign * 100 * t;} else if (type === AnimationType.SLIDE_RIGHT) {- computed.offsetX[eid] = sign * -100 * t;+ computed.offsetX[eid]! += sign * -100 * t;} else if (type === AnimationType.SLIDE_UP) {- computed.offsetY[eid] = sign * 100 * t;+ computed.offsetY[eid]! += sign * 100 * t;} else if (type === AnimationType.SLIDE_DOWN) {- computed.offsetY[eid] = sign * -100 * t;+ computed.offsetY[eid]! += sign * -100 * t;}- computed.opacity[eid] = 1 - t;+ computed.opacity[eid]! *= 1 - t;break;}case AnimationType.SPIN: {@@ -152,9 +155,9 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nuconst eased = clamp01(func(progress));const t = phase === AnimationPhase.OUT ? eased : 1 - eased;const scale = 1 - t;- computed.scaleX[eid] = scale;- computed.scaleY[eid] = scale;- computed.rotation[eid] = -45 * t;+ computed.scaleX[eid]! *= scale;+ computed.scaleY[eid]! *= scale;+ computed.rotation[eid]! -= 45 * t;break;}case AnimationType.TWIST: {@@ -163,11 +166,11 @@ function applyAnimation(world: World, entity: Entity, anim: Entity, progress: nuconst eased = clamp01(func(progress));const t = phase === AnimationPhase.OUT ? eased : 1 - eased;const scale = 1 + t;- computed.scaleX[eid] = scale;- computed.scaleY[eid] = scale;- computed.rotation[eid] = -10 * t;- computed.offsetX[eid] = -30 * t;- computed.offsetY[eid] = -30 * t;+ computed.scaleX[eid]! *= scale;+ computed.scaleY[eid]! *= scale;+ computed.rotation[eid]! -= 10 * t;+ computed.offsetX[eid]! -= 30 * t;+ computed.offsetY[eid]! -= 30 * t;break;}case AnimationType.APPEAR_WORD: {