Skip to content

Code-first video & image, rendered natively on WebGPU.

fix(components): TextReveal type and slam, unclipped component roots, LowerThird tag fit

okanasl5c18fd8fe622
diff --git a/.changeset/text-reveal-type-slam.md b/.changeset/text-reveal-type-slam.md
new file mode 100644
index 00000000..461befee
--- /dev/null
+++ b/.changeset/text-reveal-type-slam.md
@@ -0,0 +1,11 @@
+---
+"framefields": patch
+---
+
+TextReveal `type` no longer shows the whole text from the first frame when `emphasis` (or any other glyph animator) is set. The compositor dropped a text layer's `text` count track whenever the layer also had glyph animators. The two now compose, because animators index the full string. `type` also no longer reflows: each glyph switches on at its keystroke inside the full layout, so centred and wrapped lines stay put as they type, and the backspace exit removes the last glyph first.
+
+TextReveal `slam` words are no longer cut off at the text's box while they land from 2.4×. A component's root and stage boxes no longer clip, since a component's box is its footprint, not a clip. Only the `mask-*` enter and exit presets still cut to it. This also restores the full drop shadow under CodeBlock and AppFrame windows, which used to show as grey triangles at the bottom corners.
+
+LowerThird's `tag` layout scales its one-line pill down to fit the safe area, instead of running past it.
+
+Breaking for anyone who used it: TextReveal's `track` style (enter and exit) is removed. TitleCard's kicker now enters with `rise`.
diff --git a/nodes/node-compositor/src/renderers/webgpu-renderer.ts b/nodes/node-compositor/src/renderers/webgpu-renderer.ts
index 7d69d6a0..8e04ef74 100644
--- a/nodes/node-compositor/src/renderers/webgpu-renderer.ts
+++ b/nodes/node-compositor/src/renderers/webgpu-renderer.ts
@@ -3700,16 +3700,15 @@ export const CompositorWebGPURenderer: WebGPUNodeRenderer = async (args) => {
});
}
- const hasKineticAnimators =
- Array.isArray(resolvedAnimators) && resolvedAnimators.length > 0;
const hasTypewriter = Boolean(lop.typewriter || target?.typewriter);
// Check if there is an active text track or progress value evaluated by GSAP
const textTrack = lop.animation?.tracks?.find(
(t: { prop: string }) => t.prop === "text",
);
+ // Glyph animators index the full text, so they compose with a
+ // prefix reveal: the shown characters keep their indices.
const hasTextAnimation =
- !hasKineticAnimators &&
!hasTypewriter &&
(textTrack !== undefined || typeof target?.text === "number");
diff --git a/packages/components/src/core/contract.ts b/packages/components/src/core/contract.ts
index e7c6f4d7..b1409466 100644
--- a/packages/components/src/core/contract.ts
+++ b/packages/components/src/core/contract.ts
@@ -496,6 +496,10 @@ function assemble<S extends z.ZodRawShape, C extends Cues, E extends object>(
const height = props.height ?? built.height;
const blur = Math.max(enter?.blur ?? 0, exit?.blur ?? 0);
+ // The box is the component's footprint, not a clip: shadows, overshoot
+ // and landing words may reach past it. Only mask presets cut to it.
+ const masked =
+ enter?.preset.startsWith("mask-") || exit?.preset.startsWith("mask-");
const stage = host.box({
id: ctx.partId("stage"),
position: "absolute",
@@ -503,6 +507,7 @@ function assemble<S extends z.ZodRawShape, C extends Cues, E extends object>(
y: 0,
width,
height,
+ overflow: "visible",
...(blur > 0 && { motionBlurShutter: blur }),
children: built.children,
});
@@ -529,8 +534,7 @@ function assemble<S extends z.ZodRawShape, C extends Cues, E extends object>(
width,
height,
// Mask presets slide the stage through the root's own box.
- ...((enter?.preset.startsWith("mask-") ||
- exit?.preset.startsWith("mask-")) && { overflow: "hidden" as const }),
+ overflow: masked ? "hidden" : "visible",
startFrame: props.at ?? 0,
...(duration !== null && { durationFrames: duration }),
children: [stage],
diff --git a/packages/components/src/lower-third/index.test.ts b/packages/components/src/lower-third/index.test.ts
index 3ec73489..079ab561 100644
--- a/packages/components/src/lower-third/index.test.ts
+++ b/packages/components/src/lower-third/index.test.ts
@@ -37,6 +37,21 @@ describe("LowerThird", () => {
expect((plate?.x ?? 0) + (plate?.width ?? 0)).toBeCloseTo(1920 * 0.94, 5);
});
+ it("scales a one-line tag down to fit the safe area", () => {
+ const tag = find(
+ make()({
+ id: "l",
+ layout: "tag",
+ canvas: { width: 640, height: 360 },
+ name: "Ada Lovelace",
+ role: "Engineer, Analytical Engine",
+ }),
+ "l-tag",
+ );
+ // Safe area: 6 % insets each side.
+ expect(tag?.width).toBeCloseTo(640 * 0.88, 5);
+ });
+
it("leaves on its own after the hold, or stays", () => {
const l = make()({ name: "Ada", hold: 30 });
const inAt = l.cues.in[0]?.frame ?? 0;
diff --git a/packages/components/src/lower-third/index.ts b/packages/components/src/lower-third/index.ts
index 573ac4c5..8332eb8d 100644
--- a/packages/components/src/lower-third/index.ts
+++ b/packages/components/src/lower-third/index.ts
@@ -298,21 +298,25 @@ export const lowerThird = /* @__PURE__ */ defineComponent({
}
case "tag": {
// One line, one node: bold name, a dot, the role a size down.
+ // Too long for the safe area, the whole pill scales down: text
+ // width is linear in font size, so one ratio fits it exactly.
const sep = " · ";
const sepW = props.role
? host.measure(sep, { fontFamily, fontSize: roleSize }).width
: 0;
- const h = nameM.height + padY * 1.4;
- const w = nameM.width + (roleM ? sepW + roleM.width : 0) + h;
+ const h0 = nameM.height + padY * 1.4;
+ const w0 = nameM.width + (roleM ? sepW + roleM.width : 0) + h0;
+ const k = Math.min(1, safe.width / w0);
+ const [h, w] = [h0 * k, w0 * k];
const line = host.text(
props.role ? `${props.name}${sep}${props.role}` : props.name,
{
id: ctx.partId("name"),
position: "absolute",
x: h / 2,
- y: padY * 0.7,
+ y: padY * 0.7 * k,
fontFamily,
- fontSize: nameSize,
+ fontSize: nameSize * k,
fill: theme.color.ink,
spans: [
{
@@ -324,12 +328,13 @@ export const lowerThird = /* @__PURE__ */ defineComponent({
? [
{
text: `${sep}${props.role}`,
- fontSize: roleSize,
+ fontSize: roleSize * k,
fontWeight: theme.weight.medium,
fill: theme.color.muted,
// Centred on the name's capitals, not on its baseline: one
// line in a pill reads as aligned when the caps share a middle.
- baselineShift: -(nameSize - roleSize) * CAP_HEIGHT * 0.5,
+ baselineShift:
+ -(nameSize - roleSize) * k * CAP_HEIGHT * 0.5,
},
]
: []),
diff --git a/packages/components/src/text-reveal/index.test.ts b/packages/components/src/text-reveal/index.test.ts
index 41083d37..c63405f1 100644
--- a/packages/components/src/text-reveal/index.test.ts
+++ b/packages/components/src/text-reveal/index.test.ts
@@ -77,15 +77,43 @@ describe("TextReveal", () => {
expect(t.span.duration).toBeGreaterThan(exitStart);
});
- it("types with key cues, a caret, and count keys", () => {
- const t = make()({ id: "t", text: "ab c", style: "type" });
+ it("types glyph by glyph inside the full layout, and backspaces out", () => {
+ const t = make()({
+ id: "t",
+ text: "ab c",
+ style: "type",
+ exitStyle: "type",
+ emphasis: ["c"],
+ });
expect(t.cues.keystrokes).toHaveLength(3);
- const keys = track(find(t, "t-text"), "text");
- expect(keys[keys.length - 1]?.[1]).toBe(4);
- // One character is a fraction (1 would mean "all of it").
- expect(keys.map((k) => k[1])).toContain(0.25);
- expect(keys.map((k) => k[1])).not.toContain(1);
expect(find(t, "t-caret")).toBeDefined();
+ const text = find(t, "t-text");
+ // The node always holds the whole string: nothing reflows while typing.
+ expect(track(text, "text")).toEqual([]);
+ const enter = text?.animators?.find((a) => a.name === "enter");
+ expect(enter?.props).toEqual({ opacity: 0 });
+ const [first, , last] = t.cues.keystrokes;
+ const c = last?.index ?? 0;
+ expect(weight(enter as GlyphAnimator, (first?.frame ?? 0) - 1, 0)).toBe(1);
+ expect(weight(enter as GlyphAnimator, first?.frame ?? 0, 0)).toBe(0);
+ expect(weight(enter as GlyphAnimator, (last?.frame ?? 0) - 1, c)).toBe(1);
+ expect(weight(enter as GlyphAnimator, last?.frame ?? 0, c)).toBe(0);
+ // Backspace removes the last glyph first.
+ const exit = text?.animators?.find((a) => a.name === "exit");
+ const exitStart = t.cues.exitStart[0]?.frame ?? 0;
+ expect(weight(exit as GlyphAnimator, exitStart, c)).toBe(0);
+ const lastGone = t.span.duration;
+ expect(weight(exit as GlyphAnimator, lastGone, 0)).toBe(1);
+ expect(weight(exit as GlyphAnimator, lastGone - 2, 0)).toBe(0);
+ expect(weight(exit as GlyphAnimator, lastGone - 2, c)).toBe(1);
+ });
+
+ it("lets slammed words overflow their box while they land", () => {
+ const t = make()({ id: "t", text: "one two", style: "slam" });
+ const overflow = (id: string) =>
+ (find(t, id) as { overflow?: string } | undefined)?.overflow;
+ for (const id of ["t", "t-stage", "t-units", "t-shake"])
+ expect(overflow(id)).toBe("visible");
});
it("masks line by line, and only a split text can exit by mask", () => {
diff --git a/packages/components/src/text-reveal/index.ts b/packages/components/src/text-reveal/index.ts
index 855bb5c9..f105c26b 100644
--- a/packages/components/src/text-reveal/index.ts
+++ b/packages/components/src/text-reveal/index.ts
@@ -5,7 +5,6 @@
* node and its final frame is exactly the static text.
*/
import {
- type AnimatableProp,
type KeyframeTuple,
LayerAnimation,
type LayoutNode,
@@ -24,6 +23,7 @@ import {
glyphAnimator,
rendererChars,
scheduleExpression,
+ stepExpression,
type UnitSchedule,
} from "../core/glyphs.js";
import type { Animatable } from "../core/host.js";
@@ -49,7 +49,6 @@ import {
export const REVEAL_STYLES = [
"rise",
"blur",
- "track",
"mask",
"slam",
"scatter",
@@ -65,7 +64,6 @@ export type RevealStyle = (typeof REVEAL_STYLES)[number];
export const EXIT_STYLES = [
"rise",
"blur",
- "track",
"mask",
"scatter",
"type",
@@ -102,13 +100,6 @@ const STYLE: Record<RevealStyle, StyleDefaults> = {
length: 1,
ease: "power3.out",
},
- track: {
- by: "line",
- stagger: 0,
- speed: "slow",
- length: 1.5,
- ease: "expo.out",
- },
mask: {
by: "line",
stagger: 5,
@@ -330,20 +321,11 @@ export const textReveal = /* @__PURE__ */ defineComponent({
text: u.text,
}));
- // Tracking widens a line: unwrapped text gets a box with room for it,
- // placed so `align` holds while it grows.
- const tracks =
- wrap === undefined &&
- (props.style === "track" || props.exitStyle === "track");
- const room = tracks ? 0.5 * fs * Math.max(0, text.length - 1) : 0;
- const shift =
- props.align === "center" ? 0.5 : props.align === "end" ? 1 : 0;
const textNode = host.text(text, {
...textProps,
- ...(tracks && { width: W + room }),
id: ctx.partId("text"),
position: "absolute",
- x: -room * shift,
+ x: 0,
y: 0,
});
parts.text = textNode;
@@ -401,6 +383,7 @@ export const textReveal = /* @__PURE__ */ defineComponent({
return piece;
});
const landed = Math.max(0, ...unitCues.map((u) => u.settled));
+ // Words land from 2.4×: neither box may clip them on the way in.
const group = host.box({
id: ctx.partId("units"),
position: "absolute",
@@ -408,6 +391,7 @@ export const textReveal = /* @__PURE__ */ defineComponent({
y: 0,
width: W,
height: H,
+ overflow: "visible",
children: pieces,
});
group.animate(
@@ -430,6 +414,7 @@ export const textReveal = /* @__PURE__ */ defineComponent({
y: 0,
width: W,
height: H,
+ overflow: "visible",
children: [group, textNode],
});
shake.animate(...slamShake(unitCues, fs, ctx.rng("slam")));
@@ -523,11 +508,14 @@ export const textReveal = /* @__PURE__ */ defineComponent({
break;
}
case "type": {
+ // Each glyph switches on at its keystroke inside the full layout,
+ // so centred or wrapped lines never reflow while typing.
const frames = typingFrames(text, props.cps, fps, ctx.rng("type"));
- textNode.animate(
- LayerAnimation.keys(
- "text" as AnimatableProp,
- countKeys(text.length, frames),
+ animators.push(
+ glyphAnimator(
+ "enter",
+ stepExpression("char", rendererChars(text, frames)),
+ { opacity: 0 },
),
);
frames.forEach((f, i) => {
@@ -553,24 +541,6 @@ export const textReveal = /* @__PURE__ */ defineComponent({
}
break;
}
- case "track": {
- const ls = props.letterSpacing ?? 0;
- const wide = ls + 0.5 * fs;
- const fade = Math.round(duration * 0.5);
- const keys: KeyframeTuple[] = [
- [0, wide],
- [duration, ls, ease],
- ];
- const anim = LayerAnimation.create()
- .keys("letterSpacing", keys)
- .keys("opacity", [
- [0, 0],
- [fade, 1, "power2.out"],
- ]);
- textNode.animate(anim);
- unitCues = [{ frame: 0, settled: duration, index: 0, text }];
- break;
- }
case "mask": {
lines = maskLines(ctx, text, m, measureOptions, textProps, fs);
const starts = unitStarts(lines.length, stagger, props.order, ctx.seed);
@@ -693,33 +663,20 @@ export const textReveal = /* @__PURE__ */ defineComponent({
);
break;
case "type": {
- // Backspace, twice as fast as typing.
+ // Backspace, twice as fast as typing: the last glyph goes first.
const per = Math.max(1, Math.round(fps / (props.cps * 2)));
- const keys: KeyframeTuple[] = [];
- for (
- let c = text.length - 1, f = exitStart + per;
- c >= 0;
- c--, f += per
- )
- keys.push([f, c === 1 ? 1 / text.length : c, "hold"]);
- textNode.animate(LayerAnimation.keys("text" as AnimatableProp, keys));
- afterHold = per * text.length + 1;
- break;
- }
- case "track": {
- const ls = props.letterSpacing ?? 0;
- textNode.animate(
- LayerAnimation.create()
- .keys("letterSpacing", [
- [exitStart, ls],
- [exitStart + outDur, ls + 0.4 * fs, outEase],
- ])
- .keys("opacity", [
- [exitStart, 1],
- [exitStart + outDur, 0, outEase],
- ]),
+ const gone = Array.from(
+ { length: text.length },
+ (_, c) => exitStart + per * (text.length - c),
);
- afterHold = outDur;
+ animators.push(
+ glyphAnimator(
+ "exit",
+ `(1-${stepExpression("char", rendererChars(text, gone))})`,
+ { opacity: 0 },
+ ),
+ );
+ afterHold = per * text.length + 1;
break;
}
case "wipe": {
@@ -826,16 +783,6 @@ function emphasisWeights(
return w.some((v) => v > 0) ? w : null;
}
-/** Text-reveal count keys: ≤ 1 is a fraction, > 1 a character count. */
-function countKeys(length: number, frames: readonly number[]): KeyframeTuple[] {
- const keys: KeyframeTuple[] = [[0, 0]];
- frames.forEach((f, i) => {
- const c = i + 1;
- keys.push([f, c === 1 ? 1 / length : c, "hold"]);
- });
- return keys;
-}
-
/** Landing shake, per frame after a unit lands (× 0.045 em). */
const SHAKE = [0, 1, -0.55, 0.3, -0.12, 0];
diff --git a/packages/components/src/text-reveal/meta.ts b/packages/components/src/text-reveal/meta.ts
index a1cbdbd5..9523cbc2 100644
--- a/packages/components/src/text-reveal/meta.ts
+++ b/packages/components/src/text-reveal/meta.ts
@@ -3,7 +3,7 @@ import { defineMeta } from "../core/meta.js";
export default defineMeta({
name: "TextReveal",
summary:
- "Headlines and body copy that animate in and out by character, word or line: rise, blur, track, mask, slam, scatter, scramble, type, stream, wipe and flip, each ending on exactly the static text.",
+ "Headlines and body copy that animate in and out by character, word or line: rise, blur, mask, slam, scatter, scramble, type, stream, wipe and flip, each ending on exactly the static text.",
tags: ["text", "typography", "kinetic type", "title", "reveal", "typewriter"],
parts: ["text", "shake", "caret", "matte", "reels", "units", "line-<n>"],
cues: ["units", "revealed", "exitStart", "keystrokes"],
diff --git a/packages/components/src/title-card/index.ts b/packages/components/src/title-card/index.ts
index a8f3cd76..3de7fcbe 100644
--- a/packages/components/src/title-card/index.ts
+++ b/packages/components/src/title-card/index.ts
@@ -179,7 +179,7 @@ export const titleCard = /* @__PURE__ */ defineComponent({
const kicker = reveal({
id: ctx.partId("kicker"),
text: kickerText,
- style: "track",
+ style: "rise",
...place.kicker,
fontFamily,
fontSize: kickerSize,