Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
Add text animation presets for annotations
Justice Entsie62000c6dcfbe
diff --git a/src/components/video-editor/AnnotationOverlay.tsx b/src/components/video-editor/AnnotationOverlay.tsxindex 345423f5d..13d245b8a 100644--- a/src/components/video-editor/AnnotationOverlay.tsx+++ b/src/components/video-editor/AnnotationOverlay.tsx@@ -1,5 +1,6 @@import { type CSSProperties, type PointerEvent, useEffect, useRef, useState } from "react";import { Rnd } from "react-rnd";+import { getTextAnimationState } from "@/lib/annotationTextAnimation";import {getBlurOverlayColor,getMosaicGridOverlayColor,@@ -50,6 +51,7 @@ interface AnnotationOverlayProps {isSelectedBoost: boolean; // Boost z-index when selected for easy editingpreviewSourceCanvas?: PreviewCanvasSource | null;previewFrameVersion?: number;+ currentTimeMs: number;}export function AnnotationOverlay({@@ -66,6 +68,7 @@ export function AnnotationOverlay({isSelectedBoost,previewSourceCanvas,previewFrameVersion,+ currentTimeMs,}: AnnotationOverlayProps) {const committedX = (annotation.position.x / 100) * containerWidth;const committedY = (annotation.position.y / 100) * containerHeight;@@ -283,7 +286,12 @@ export function AnnotationOverlay({const renderContent = () => {switch (annotation.type) {- case "text":+ case "text": {+ const animationState = getTextAnimationState(annotation, currentTimeMs);+ const typewriterClip =+ animationState.revealProgress < 1+ ? `inset(0 ${100 - animationState.revealProgress * 100}% 0 0)`+ : undefined;return (<divclassName="w-full h-full flex items-center p-2 overflow-hidden"@@ -307,6 +315,11 @@ export function AnnotationOverlay({fontStyle: annotation.style.fontStyle,textDecoration: annotation.style.textDecoration,textAlign: annotation.style.textAlign,+ opacity: animationState.opacity,+ transform: `translate(${animationState.translateX}px, ${animationState.translateY}px) scale(${animationState.scale})`,+ transformOrigin: "center",+ clipPath: typewriterClip,+ WebkitClipPath: typewriterClip,wordBreak: "break-word",whiteSpace: "pre-wrap",boxDecorationBreak: "clone",@@ -320,6 +333,7 @@ export function AnnotationOverlay({</span></div>);+ }case "image":if (annotation.content && annotation.content.startsWith("data:image")) {diff --git a/src/components/video-editor/AnnotationSettingsPanel.tsx b/src/components/video-editor/AnnotationSettingsPanel.tsxindex 5559b34d9..300bd663d 100644--- a/src/components/video-editor/AnnotationSettingsPanel.tsx+++ b/src/components/video-editor/AnnotationSettingsPanel.tsx@@ -28,6 +28,7 @@ import { Slider } from "@/components/ui/slider";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group";import { useScopedT } from "@/contexts/I18nContext";+import { normalizeTextAnimation, TEXT_ANIMATION_OPTIONS } from "@/lib/annotationTextAnimation";import { type CustomFont, getCustomFonts } from "@/lib/customFonts";import { cn } from "@/lib/utils";import ColorPicker from "../ui/color-picker";@@ -306,6 +307,29 @@ export function AnnotationSettingsPanel({/></div>+ <div>+ <label className="mb-2 block text-xs font-medium text-slate-200">+ Text Animation+ </label>+ <Select+ value={normalizeTextAnimation(annotation.style.textAnimation)}+ onValueChange={(value) =>+ onStyleChange({ textAnimation: normalizeTextAnimation(value) })+ }+ >+ <SelectTrigger className="h-9 w-full border-white/10 bg-white/5 text-xs text-slate-200">+ <SelectValue placeholder="Select animation" />+ </SelectTrigger>+ <SelectContent className="max-h-[240px] border-white/10 bg-[#1a1a1c] text-slate-200">+ {TEXT_ANIMATION_OPTIONS.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ </div>+{/* Formatting Toggles */}<div className="flex items-center justify-between gap-2"><ToggleGroupdiff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsxindex 28c7b50a6..3b5a93ec5 100644--- a/src/components/video-editor/VideoPlayback.tsx+++ b/src/components/video-editor/VideoPlayback.tsx@@ -2044,6 +2044,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(}previewSourceCanvas={previewSnapshotCanvas}previewFrameVersion={Math.round(currentTime * 1000)}+ currentTimeMs={Math.round(currentTime * 1000)}/>));})()}diff --git a/src/components/video-editor/projectPersistence.ts b/src/components/video-editor/projectPersistence.tsindex f16d29ea0..1e4914719 100644--- a/src/components/video-editor/projectPersistence.ts+++ b/src/components/video-editor/projectPersistence.ts@@ -1,3 +1,4 @@+import { normalizeTextAnimation } from "@/lib/annotationTextAnimation";import { normalizeBlurColor, normalizeBlurType } from "@/lib/blurEffects";import type { ExportFormat, ExportQuality, GifFrameRate, GifSizePreset } from "@/lib/exporter";import type { ProjectMedia } from "@/lib/recordingSession";@@ -366,6 +367,7 @@ export function normalizeProjectEditor(editor: Partial<ProjectEditorState>): Prostyle: {...DEFAULT_ANNOTATION_STYLE,...(region.style && typeof region.style === "object" ? region.style : {}),+ textAnimation: normalizeTextAnimation(region.style?.textAnimation),},zIndex: isFiniteNumber(region.zIndex) ? region.zIndex : index + 1,figureData: region.figureDatadiff --git a/src/components/video-editor/types.ts b/src/components/video-editor/types.tsindex fce4a199a..0f2267cca 100644--- a/src/components/video-editor/types.ts+++ b/src/components/video-editor/types.ts@@ -255,6 +255,15 @@ export interface AnnotationSize {height: number;}+export type AnnotationTextAnimation =+ | "none"+ | "fade"+ | "rise"+ | "pop"+ | "slide-left"+ | "typewriter"+ | "pulse";+export interface AnnotationTextStyle {color: string;backgroundColor: string;@@ -264,6 +273,7 @@ export interface AnnotationTextStyle {fontStyle: "normal" | "italic";textDecoration: "none" | "underline";textAlign: "left" | "center" | "right";+ textAnimation?: AnnotationTextAnimation;}export interface AnnotationRegion {@@ -301,6 +311,7 @@ export const DEFAULT_ANNOTATION_STYLE: AnnotationTextStyle = {fontStyle: "normal",textDecoration: "none",textAlign: "center",+ textAnimation: "none",};export const DEFAULT_FIGURE_DATA: FigureData = {diff --git a/src/lib/annotationTextAnimation.test.ts b/src/lib/annotationTextAnimation.test.tsnew file mode 100644index 000000000..205d93d05--- /dev/null+++ b/src/lib/annotationTextAnimation.test.ts@@ -0,0 +1,50 @@+import { describe, expect, it } from "vitest";+import { getTextAnimationState, normalizeTextAnimation } from "./annotationTextAnimation";++describe("annotation text animations", () => {+ it("normalizes unknown animation values to none", () => {+ expect(normalizeTextAnimation("rise")).toBe("rise");+ expect(normalizeTextAnimation("not-real")).toBe("none");+ expect(normalizeTextAnimation(undefined)).toBe("none");+ });++ it("returns a settled state when animation is disabled", () => {+ expect(+ getTextAnimationState(+ {+ startMs: 1000,+ style: { textAnimation: "none" },+ },+ 1000,+ ),+ ).toEqual({+ opacity: 1,+ scale: 1,+ translateX: 0,+ translateY: 0,+ revealProgress: 1,+ });+ });++ it("eases rise animations into place over time", () => {+ const initial = getTextAnimationState(+ {+ startMs: 1000,+ style: { textAnimation: "rise" },+ },+ 1000,+ );+ const settled = getTextAnimationState(+ {+ startMs: 1000,+ style: { textAnimation: "rise" },+ },+ 2000,+ );++ expect(initial.opacity).toBe(0);+ expect(initial.translateY).toBeGreaterThan(0);+ expect(settled.opacity).toBe(1);+ expect(settled.translateY).toBe(0);+ });+});diff --git a/src/lib/annotationTextAnimation.ts b/src/lib/annotationTextAnimation.tsnew file mode 100644index 000000000..13878a423--- /dev/null+++ b/src/lib/annotationTextAnimation.ts@@ -0,0 +1,130 @@+import type { AnnotationTextAnimation } from "@/components/video-editor/types";++export const TEXT_ANIMATION_DURATION_MS = 700;++export interface TextAnimationState {+ opacity: number;+ scale: number;+ translateX: number;+ translateY: number;+ revealProgress: number;+}++export const TEXT_ANIMATION_OPTIONS: Array<{+ value: AnnotationTextAnimation;+ label: string;+}> = [+ { value: "none", label: "None" },+ { value: "fade", label: "Fade" },+ { value: "rise", label: "Rise" },+ { value: "pop", label: "Pop" },+ { value: "slide-left", label: "Slide" },+ { value: "typewriter", label: "Typewriter" },+ { value: "pulse", label: "Pulse" },+];++function clamp(value: number, min = 0, max = 1) {+ return Math.min(max, Math.max(min, value));+}++function easeOutCubic(value: number) {+ const t = clamp(value);+ return 1 - (1 - t) ** 3;+}++function easeOutBack(value: number) {+ const t = clamp(value);+ const c1 = 1.70158;+ const c3 = c1 + 1;+ return 1 + c3 * (t - 1) ** 3 + c1 * (t - 1) ** 2;+}++export function normalizeTextAnimation(value: unknown): AnnotationTextAnimation {+ return TEXT_ANIMATION_OPTIONS.some((option) => option.value === value)+ ? (value as AnnotationTextAnimation)+ : "none";+}++export function getTextAnimationState(+ annotation: {+ startMs: number;+ style: {+ textAnimation?: AnnotationTextAnimation;+ };+ },+ currentTimeMs: number,+): TextAnimationState {+ const animation = normalizeTextAnimation(annotation.style.textAnimation);+ if (animation === "none") {+ return {+ opacity: 1,+ scale: 1,+ translateX: 0,+ translateY: 0,+ revealProgress: 1,+ };+ }++ const elapsedMs = Math.max(0, currentTimeMs - annotation.startMs);+ const progress = clamp(elapsedMs / TEXT_ANIMATION_DURATION_MS);+ const eased = easeOutCubic(progress);++ switch (animation) {+ case "fade":+ return {+ opacity: eased,+ scale: 1,+ translateX: 0,+ translateY: 0,+ revealProgress: 1,+ };+ case "rise":+ return {+ opacity: eased,+ scale: 1,+ translateX: 0,+ translateY: (1 - eased) * 18,+ revealProgress: 1,+ };+ case "pop":+ return {+ opacity: eased,+ scale: Math.max(0.72, easeOutBack(progress)),+ translateX: 0,+ translateY: 0,+ revealProgress: 1,+ };+ case "slide-left":+ return {+ opacity: eased,+ scale: 1,+ translateX: (1 - eased) * -28,+ translateY: 0,+ revealProgress: 1,+ };+ case "typewriter":+ return {+ opacity: 1,+ scale: 1,+ translateX: 0,+ translateY: 0,+ revealProgress: progress,+ };+ case "pulse":+ return {+ opacity: 1,+ scale: 1 + Math.sin(progress * Math.PI) * 0.06,+ translateX: 0,+ translateY: 0,+ revealProgress: 1,+ };+ default:+ return {+ opacity: 1,+ scale: 1,+ translateX: 0,+ translateY: 0,+ revealProgress: 1,+ };+ }+}diff --git a/src/lib/exporter/annotationRenderer.ts b/src/lib/exporter/annotationRenderer.tsindex c0d5657f5..31cd836ff 100644--- a/src/lib/exporter/annotationRenderer.ts+++ b/src/lib/exporter/annotationRenderer.ts@@ -1,4 +1,5 @@import { type AnnotationRegion, type ArrowDirection } from "@/components/video-editor/types";+import { getTextAnimationState } from "@/lib/annotationTextAnimation";import {applyMosaicToImageData,getBlurOverlayColor,@@ -242,11 +243,21 @@ function renderText(width: number,height: number,scaleFactor: number,+ currentTimeMs: number,) {const style = annotation.style;+ const animationState = getTextAnimationState(annotation, currentTimeMs);ctx.save();+ const transformOriginX = x + width / 2;+ const transformOriginY = y + height / 2;+ ctx.translate(transformOriginX, transformOriginY);+ ctx.translate(animationState.translateX * scaleFactor, animationState.translateY * scaleFactor);+ ctx.scale(animationState.scale, animationState.scale);+ ctx.translate(-transformOriginX, -transformOriginY);+ ctx.globalAlpha *= animationState.opacity;+// Clip text to annotation box bounds (matches editor's overflow: hidden)ctx.beginPath();ctx.rect(x, y, width, height);@@ -301,9 +312,13 @@ function renderText(lines.forEach((line, index) => {const currentY = startY + index * lineHeight;+ const revealProgress = animationState.revealProgress;+ const visibleLine =+ revealProgress >= 1 ? line : line.slice(0, Math.ceil(line.length * revealProgress));+ if (!visibleLine && revealProgress < 1) return;if (style.backgroundColor && style.backgroundColor !== "transparent") {- const metrics = ctx.measureText(line);+ const metrics = ctx.measureText(visibleLine);const verticalPadding = scaledFontSize * 0.1;const horizontalPadding = scaledFontSize * 0.2;const borderRadius = 4 * scaleFactor;@@ -328,10 +343,10 @@ function renderText(}ctx.fillStyle = style.color;- ctx.fillText(line, textX, currentY);+ ctx.fillText(visibleLine, textX, currentY);if (style.textDecoration === "underline") {- const metrics = ctx.measureText(line);+ const metrics = ctx.measureText(visibleLine);let underlineX = textX;const underlineY = currentY + scaledFontSize * 0.15;@@ -420,7 +435,7 @@ export async function renderAnnotations(switch (annotation.type) {case "text":- renderText(ctx, annotation, x, y, width, height, scaleFactor);+ renderText(ctx, annotation, x, y, width, height, scaleFactor, currentTimeMs);break;case "image":