@video-ultra/react
The editor component, its controller, hooks and theming. Re-exports the core types you need.
npm install @video-ultra/reactNames marked core are re-exported from @video-ultra/core and documented there — import them from either package.
Components
VideoEditor
componentThe video editor. Drop it anywhere — it fills its container and picks the phone, tablet or desktop layout from its own width (container queries), not the window's.
import { VideoEditor } from '@video-ultra/react';
import '@video-ultra/react/styles.css';
<VideoEditor onSave={(project) => save(project)} onExport={({ blob }) => upload(blob)} />function VideoEditor(props: VideoEditorProps): ReactElement;Hooks
useController
hookThe controller of the surrounding <VideoEditor />.
function useController(): EditorController;useHistory
hookUndo/redo availability and labels.
function useHistory(): {
canUndo: boolean;
canRedo: boolean;
undoLabel: string | null;
redoLabel: string | null;
};useLabels
hookThe editor's labels (i18n).
function useLabels(): Labels;useProject
hookPart of the project as the editor shows it (inside an open combined clip, its inside), re-rendering only when it changes (shallow compare).
function useProject<T>(selector: (project: Project) => T): T;useUi
hookUI state, re-rendering only when the selected slice changes (shallow compare).
function useUi<T>(selector: (state: UiState) => T): T;Functions
createStarterSounds
functionThe starter sound effects as an AudioLibrary (opt-in: pass it, or merge its tracks into your own source). Sounds are made on first use and kept in memory while the page is open.
import { VideoEditor, createStarterSounds } from '@video-ultra/react';
<VideoEditor audioLibrary={createStarterSounds()} />function createStarterSounds(options?: {
labels?: Partial<StarterSoundLabels>;
}): AudioLibrary;themeOverridesToStyle
functionTurns ThemeOverrides into inline CSS variables for .vu-root.
function themeOverridesToStyle(overrides: ThemeOverrides | undefined): CSSProperties;Classes
EditorController
classclass EditorController {
#private;
readonly editor: Editor;
readonly ui: zustand.StoreApi<UiState>;
readonly playhead: Playhead;
/** Sound levels while playing (meters). */
readonly levels: Levels;
readonly labels: Labels;
readonly options: ControllerOptions;
analyzer: MediaAnalyzer | null;
storage: ProjectStorage | null;
engine: Engine | null;
caps: Capabilities | null;
/** Bytes of every asset, for the engine and analyzer (Files/Blobs: no copies in memory). */
readonly media: Map<string, Blob>;
/** Listens to what happens in the editor (edits, selection, playback, …); returns an unsubscribe. */
on(listener: (event: EditorEvent) => void): () => void;
/** Tells the listeners (a host's listener throwing never breaks the editor). */
notify(event: EditorEvent): void;
constructor(options: ControllerOptions, project?: Project);
/** Opens the file picker (the shell registers it). */
/** Opens the file picker; `start`: what's picked goes before the first clip. */
pickFiles(place?: 'playhead' | 'start'): void;
/** Where the files from the last `pickFiles` go (read once by the picker's change handler). */
takePickPlace(): 'playhead' | 'start';
/** Registers the shell's file picker; returns an unregister function. */
setFilePicker(open: (() => void) | null): () => void;
/** The project as the editor shows it: inside the open combined clip, if one is open. */
get project(): Project;
/**
* `project` as the editor shows it: with a combined clip open, a project whose
* tracks are its inside, drawn at its size (no markers or export range — those are the whole
* video's). Cached per project object, so selectors stay stable.
*/
view(project: Project): Project;
/** Storage, analyzer, autosave, and media for the opening project. */
start(caps: Capabilities, initial: Project | null): Promise<void>;
/**
* "Allow": asks the browser again for every kept file waiting for the person's OK. Call it
* straight from a tap (browsers only ask inside one). Files still refused move on to "Find".
*/
allowMediaAccess(): Promise<void>;
/**
* "Find": the person picked a missing file again. It must be the same kind of media (a video
* for a video…); it's stored like an import and the asset points at it — one undo step, items
* keep their times. Returns false (with a message) when the file doesn't fit.
*/
relinkMedia(assetId: string, file: File): Promise<boolean>;
/** Hides the media banner (the files stay missing; their clips show without a picture). */
dismissMediaProblems(): void;
/**
* "Use it here": takes the project over from the other tab, reloads what that tab saved, and
* saves from this tab from now on.
*/
takeOver(): Promise<void>;
/** The videos saved on this device, newest first (empty when the editor doesn't save here). */
listVideos(): Promise<StoredProjectInfo[]>;
/**
* Makes a copy of this video and opens it: the same media files (nothing is copied but the
* project), a new name, its own history. The original stays as it was saved.
*/
duplicateVideo(): Promise<void>;
/** Opens another saved video (the current one is saved first). */
openVideo(id: string): Promise<void>;
/** Starts a new, empty video (the current one is saved first and stays in the list). */
newVideo(): Promise<void>;
/** Deletes a saved video other than the open one, and media only it used. */
deleteVideo(id: string): Promise<void>;
/** Hands the preview canvas to a new engine worker. Returns a disposer. */
attachCanvas(canvas: HTMLCanvasElement): Promise<() => void>;
/**
* Stops everything start() and attachCanvas() began (autosave, analyzer, engine). The controller
* can be started again — React strict mode unmounts and remounts once in development.
*/
stop(): void;
togglePlay(): void;
play(): void;
pause(): void;
/** Moves the playhead. Engine seeks are coalesced to one per animation frame (latest wins). */
seek(time: Time): void;
/**
* Shows the frame at `time` in the preview without moving the playhead (trimming shows the new
* edge); `null` returns the preview to the playhead. Coalesced per frame.
*/
previewSeek(time: Time | null): void;
/** Steps by whole frames (arrow keys). */
step(frames: number): void;
/** While set (a call through `fanOutController`), edits also reach these selected items. */
fanOut: readonly string[] | null;
/**
* Shows a not-yet-committed version of the project in the preview (stage drags, sliders before
* release). Nothing is written to the store or the undo history. Coalesced per frame.
*/
preview(recipe: ((draft: Project, ctx: EditContext) => void) | null): Project | null;
/**
* Called (at most once a frame) with each preview shown, and with `null` when it ends. For views
* that follow the picture while a slider or drag is in progress; returns an unsubscribe.
*/
onPreview(fn: (project: Project | null) => void): () => void;
/**
* Turns an item from `from` to `to` (a quarter turn, a mirror-turn) with a short ease on the
* video — previews only, view-only — then commits one edit. Reduced motion: at once. A second
* turn while one runs finishes the first at once.
*/
/**
* Mirrors an item (`to` has the new flip) with a short ease on the video: it eases a little
* smaller, flips at the midpoint, and eases back (the transform has no in-between for a
* mirror). Previews only, then one edit; reduced motion: at once.
*/
flipItem(label: string, itemId: string, time: Time, from: Transform, to: Transform): void;
turnItem(label: string, itemId: string, time: Time, from: Transform, to: Transform): void;
/**
* A preview is on screen: the engine has drawn a frame with it (the stage moves its own
* selection frame then on touch, so frame and picture move together).
*/
onPreviewDrawn(fn: (project: Project) => void): () => void;
/** Runs an edit; refused edits show their reason instead of throwing. */
run<R>(label: string, recipe: (draft: Project, ctx: EditContext) => R, options?: {
coalesceKey?: string;
}): R | undefined;
undo(): void;
redo(): void;
/** History panel: undoes or redoes until `position` steps are applied (0 = as opened). */
jumpToHistory(position: number): void;
/**
* Selects an item (closing any open tool, since tools belong to the selection). `keepPanel`
* keeps the open panel/tool — used when a panel selects the clip it is about to act on.
* Picking a group member selects the whole group (`only` picks just that member); `add`
* toggles the item (and its group) in a multi-selection (Shift-click, Layers "Select several").
*/
select(itemId: string | null, options?: {
keepPanel?: boolean;
add?: boolean;
only?: boolean;
}): void;
selectedItem(): Item | null;
/** Everything selected (one item, a group, or a multi-selection). */
selectedItems(): Item[];
/** Whether an item can't be changed: locked itself, or on a locked row. */
isLocked(itemId: string): boolean;
/** ⌘A: every element on screen at the playhead (not the main video, not hidden ones). */
selectAll(): void;
/** Locks or unlocks the selection (all locked → unlock all). */
toggleLockSelected(): void;
/** Hides or shows the selection (all hidden → show all). */
toggleHideSelected(): void;
/** One row of the Layers panel: lock / hide / rename a single item. */
setItemLocked(itemId: string, locked: boolean): void;
setItemHidden(itemId: string, hidden: boolean): void;
renameItem(itemId: string, name: string): void;
/** Lane header: locks or unlocks a whole row. */
toggleTrackLock(trackId: string): void;
/** Why the selection can't be grouped (null = it can). */
groupReason(): string | null;
groupSelected(): void;
/** Whether `item` plays a combined clip. */
isCombined(item: Item | null | undefined): boolean;
/** Why the selection can't be combined (null = it can). */
combineReason(): string | null;
/** Combines the selection into one clip and selects it. */
combineSelected(): void;
/**
* Opens a combined clip to edit its inside (the selected one, or `itemId`): the timeline shows
* what's in it, the playhead at the same moment of it. Edits change every place that plays it.
*/
openCombined(itemId?: string): void;
/** Back out of the open combined clip (`all`: back to the timeline itself). */
closeCombined(all?: boolean): void;
/** Puts the selected combined clip's pieces back on the timeline. */
separateSelected(): void;
/** The group the selection is (null when it isn't exactly one group). */
selectedGroup(): string | null;
ungroupSelected(): void;
/** Why the selection can't move in the stack (null = it can). */
arrangeReason(to: ArrangeTo): string | null;
arrangeSelected(to: ArrangeTo): void;
/**
* Layers panel drag: puts an element at `toIndex` in the on-screen stack (0 = front), one step
* at a time so lanes stay tidy. One undo step.
*/
moveInStack(itemId: string, toIndex: number): void;
alignReason(): string | null;
distributeReason(): string | null;
/** Lines up the selection: one element against the frame, several against each other. */
align(edge: AlignEdge): void;
distribute(axis: 'x' | 'y'): void;
/**
* Opens or closes Layers or History (top bar): the left panel on desktop / tablet, the sheet on
* phones.
*/
toggleSidePanel(id: 'layers' | 'history'): void;
/** Opens the context menu for the selection at a point in the editor root (px). */
openMenu(x: number, y: number): void;
closeMenu(): void;
openTool(tool: ToolId | null): void;
openPanel(panel: PanelId | null): void;
/** The ratio button: video settings live in the inspector (desktop) or the dock (phone/tablet). */
openCanvasSettings(): void;
/** The editor's root element (preview mode's fullscreen target). */
setRoot(root: HTMLElement | null): void;
setPreviewMode(on: boolean): void;
/** The timeline registers how to zoom around the playhead. */
setZoomHandler(handler: ((factor: number) => void) | null): () => void;
zoom(factor: number): void;
setLayout(layout: LayoutMode): void;
/** The item to split/freeze: the selection, or the main clip under the playhead. */
/** What each action would act on now (shared with the buttons, see targets.ts). */
targets(): Targets;
/** Splits the selection (or the main clip under the playhead) at the playhead. */
split(): void;
deleteSelected(): void;
duplicateSelected(): void;
/** Copies the selection (and the media it uses) for {@link paste}. */
copySelected(): number;
/** Copies the selection, then deletes it. */
cutSelected(): void;
/** Whether {@link paste} has something to paste. */
hasClipboard(): boolean;
/** Pastes what was copied at the playhead, and selects it. */
paste(): void;
freezeSelected(): void;
onCut(listener: (t: Time) => void): () => void;
/** Copies a video's sound to an audio lane and mutes the video, so it can be edited alone. */
extractAudio(): void;
/** Sets (or clears) a clip's filter; keeps the intensity the user chose. */
applyFilter(item: Item, filterId: string | null): void;
/**
* Gives every video and photo (main track and layers) the look of `from`: its filter at its
* strength, and its LUT look. Locked ones are left alone. Returns how many changed.
*/
applyFilterToAll(from: Item): number;
/**
* Plays `from`…`to` once and pauses (a preview after picking a transition or an animation).
* Any user play/pause/seek in between cancels the auto-stop.
*/
playRange(from: Time, to: Time): void;
/** Sets (or clears) the transition into a main-track clip. */
applyTransition(item: Item, type: string | null, duration: Time): void;
/** The same transition between every pair of main-track clips. */
applyTransitionToAll(type: string, duration: Time): void;
/** Lane header toggle: mutes the main track and audio lanes, hides visual lanes. */
toggleTrack(trackId: string): void;
/** Adds an overlay/lane item at the playhead and selects it. */
/** Adds a marker at the playhead (key M) — or removes the one that's there. */
addMarkerHere(): void;
/** The nearest marker after (1) or before (−1) the playhead, or null. */
markerNear(direction: 1 | -1): Time | null;
/** Adds a template at the playhead (one group) and selects it. */
addTemplate(template: TemplatePreset, values: Readonly<Record<string, string>>): void;
addLaneItem(label: string, make: (id: string, start: Time) => Item): void;
/**
* Resolves once an asset's file is attached (the analyzer and engine have it): at once if it
* is, else when it arrives. A project opens before its media is read back from storage, so
* thumbnails wait for this instead of asking too early. Resolves (no wait) if `signal` aborts.
*/
whenMedia(assetId: string, signal?: AbortSignal): Promise<void>;
/** Lighter copies in use for previews, by asset id (device-local, not in the project). */
readonly proxies: Map<string, File>;
/**
* Imports files: probe (in a worker), store, register, and add to the timeline — videos and
* photos after the clip under the playhead, audio on a lane at the playhead. Each file fails on
* its own with a clear message.
*/
importFiles(files: readonly File[], options?: {
addToTimeline?: boolean;
asSticker?: boolean;
/** Licence / attribution line kept on the asset (library sounds). */
credit?: string;
/** Display name instead of the file name (library sounds: their title). */
name?: string;
/** Select the added sound clip (library sounds: its settings show next). */
selectSound?: boolean;
/** Videos and photos go before the first clip (in the order given), not at the playhead. */
atStart?: boolean;
/** Sounds go here instead of the playhead (a voiceover: where its recording started). */
at?: Time;
/**
* Added sounds play at this speed with their pitch kept (text to speech from a service
* that can't change its pace). Default 1.
*/
speed?: number;
}): Promise<void>;
/** Adds an already-imported asset to the timeline (media panel). */
addAssetToTimeline(assetId: string): void;
dismissImport(rowId: string): void;
/** Why "Lower under voice" can't act on the selection now (null: it can). */
duckReason(): string | null;
/** Turns "Lower under voice" on (default amount) or off for the selected music, sounds, clips. */
toggleDuckSelected(): void;
/**
* Whether anything in the project can be heard for ducked items to lower under: a sounding
* item (not `exceptId`, not itself ducked, not muted) whose media has sound.
*/
hasVoiceFor(exceptId: string, project?: Project): boolean;
/**
* Adds a sound from the host's library at the playhead (on a sound lane) and selects it. The
* file is stored in the project like an import; its licence line goes on the asset.
*/
addLibrarySound(track: AudioLibraryTrack, signal?: AbortSignal): Promise<boolean>;
/** Adds a blurred or pixelated box / oval at the playhead, selected (it can be dragged at once). */
addRegion(effect: RegionItem['effect'], shape: RegionItem['shape']): void;
/**
* Green screen "pick from video": the next tap on the stage picks `itemId`'s key colour
* (`null` stops picking).
*/
startPicking(itemId: string | null): void;
/**
* Picks the key colour of the item being picked for, at canvas point `x, y` (fractions): the
* picture's own colour there (without its green screen), from the engine.
*/
pickKeyColour(x: number, y: number): Promise<void>;
/**
* Imports a `.cube` LUT: checked in the engine worker (clear message when it can't be used),
* stored like media (never inlined in the project), added as a `lut` asset (to the LUT looks
* list) and applied to `itemId` when that is an unlocked picture; the toast says which.
*/
importLut(file: File, itemId: string | null): Promise<void>;
/** Renders the project to a video file (the engine pauses preview meanwhile). */
exportVideo(options: ExportOptions, onProgress: (p: ExportProgress) => void, signal: AbortSignal): Promise<ExportResult>;
/**
* The part to export starts at the playhead (key I). Its end stays where it was, or is the end
* of the video when there was none (or it came before the new start).
*/
setExportIn(): void;
/** The part to export ends at the playhead (key O); its start stays, or is the video's start. */
setExportOut(): void;
/** Sets (or clears, `null`) the part to export as one undoable edit. */
setExportRange(range: {
start: Time;
end: Time;
} | null): void;
/** Exports only the sound (the same mix as the video export). */
exportAudio(options: AudioExportOptions, onProgress: (p: ExportProgress) => void, signal: AbortSignal): Promise<AudioExportResult>;
/** Saves the frame under the playhead as a picture at the project's size. */
saveFrame(options: FrameImageOptions): Promise<FrameImage>;
/** Opens / closes the camera recorder (it covers the editor while open). */
setCameraOpen(open: boolean): void;
/**
* Adds a finished camera recording (already streamed into storage as `assetId`): probed like an
* import, then placed in the main video at the playhead or as a layer over it. Returns false
* (after saying why) when the file can't be used.
*/
addRecording(file: File, assetId: string, source: Asset['source'], place: 'main' | 'layer'): Promise<boolean>;
toast(message: string, tone?: 'info' | 'error' | 'success', action?: {
label: string;
run: () => void;
}): void;
dismissToast(id: number): void;
/** Validates a host-provided project (JSON or object). */
static parse(input: unknown): {
project: Project | null;
error: string | null;
};
/** Whether background removal can run here (null: the host gave no remover). */
checkBackgroundRemoval(): Promise<BackgroundRemoverCheck | null>;
/**
* Whether a sticker image has a background to remove: not when it's animated (a cut-out is one
* still picture — the animation would stop) or already see-through at its edges (library
* stickers, cut-out logos). `null` while not known yet: the check runs once per asset, off the
* main thread's way (header bytes, a 48 px decode), and bumps `stickerChecks` when done.
*/
stickerHasBackground(assetId: string): boolean | null;
removeBackground(itemId: string): Promise<void>;
cancelBackgroundRemoval(): void;
/** Shows the photo's own background again. */
restoreBackground(itemId: string): void;
/**
* Speaks `text` with the host's voice service and adds it as a sound clip at `at` (default:
* the playhead). Progress: `ui.speechBusy`. Returns false when it failed or was stopped.
*/
speak(text: string, options?: {
voice?: string;
speed?: number;
at?: number;
}): Promise<boolean>;
/** Stops a running {@link speak}. */
cancelSpeech(): void;
/**
* Sends `instruction` to the host's assistant with a description of the project, then applies
* the edits it answers with as one undo step — all of them or, if one is invalid, none (the
* reason shows in the conversation). Returns the turn.
*/
askAssistant(instruction: string): Promise<AssistantTurn | null>;
/**
* Undoes an assistant turn's changes — only while they're still the latest step (otherwise
* undo would take back something else). Returns whether it did.
*/
undoAssistantTurn(id: number): boolean;
/** Stops a request to the assistant. */
cancelAssistant(): void;
/**
* Finds where the scenes change in a video clip (in the analyzer worker, frame by frame) and
* splits the clip there — one undo step. Progress is in `ui.sceneJob`. Returns the number of
* parts (1 = no scene changes), or `null` when stopped or the video couldn't be read.
*/
splitAtScenes(itemId: string, sensitivity?: SceneSensitivity): Promise<number | null>;
/** Stops a running {@link splitAtScenes}. */
cancelSceneDetection(): void;
/** Whether auto captions can run, and what they'd take, for `language`. */
checkCaptions(language: string): Promise<TranscriberCheck | null>;
/**
* Auto captions: the video's speech (music lowered under voice is left out, so the words come
* through) goes to the transcriber piece by piece; the words become captions that replace any
* there were — only those in `options.range` when it's given (a part heard again). One undo
* step. Progress is in `ui.captionJob`; `cancelCaptions()` stops it.
*/
autoCaptions(language: string, options?: CaptionOptions): Promise<void>;
cancelCaptions(): void;
/** Reads an .srt / .vtt file into captions (replacing any). */
importSubtitles(file: File): Promise<void>;
/** The captions as subtitle cues (for .srt / .vtt). */
captionCues(): SubtitleCue[];
/** Downloads the captions as a subtitle file. */
downloadSubtitles(format: 'srt' | 'vtt'): void;
/** Adds a caption to type at the playhead (2 s, or up to the next one). */
addCaptionHere(): void;
setCaptionText(itemId: string, text: string): void;
mergeCaption(itemId: string): void;
/** The "check this" mark goes: a person read the caption and it's right. */
markCaptionChecked(itemId: string): void;
/**
* Hears one caption's part of the video again (half a second either side), the way the last
* auto captions were made, and replaces the captions there.
*/
hearCaptionAgain(itemId: string): void;
/** Selects and plays to the next caption marked to check (after the selected one). */
nextCaptionToCheck(): void;
/** Restyles every caption (one undo step per change; a slider drag is one). */
setCaptionLook(patch: CaptionLookPatch, coalesceKey?: string): void;
}Levels
classSound levels while playing (v0.4 meters): the loudest sample per side just heard, 0…1. Updated per frame from the engine; components subscribe and draw through refs (no renders).
class Levels {
#private;
left: number;
right: number;
set(left: number, right: number): void;
subscribe(listener: (left: number, right: number) => void): () => void;
}Playhead
classThe playhead time (flicks). Changes every frame while playing, so it is NOT React state: subscribers (timecode text, timeline canvas) update themselves.
class Playhead {
#private;
get time(): number;
set(time: number): void;
subscribe(listener: (time: number) => void): () => void;
}Constants
DEFAULT_LABELS
constantEvery piece of text the editor shows. Pass a partial labels object to <VideoEditor /> to translate or reword; missing keys fall back to English. Functions receive values to place.
const DEFAULT_LABELS: {
readonly close: "Close";
readonly undo: "Undo";
readonly redo: "Redo";
readonly undoWhat: (what: string) => string;
readonly redoWhat: (what: string) => string;
readonly projectName: "Project name";
readonly aspectRatio: "Canvas size";
readonly export: "Export";
readonly resizePanel: "Resize the side panel";
readonly resizeInspector: "Resize the settings panel";
readonly resizeTimeline: "Resize the timeline";
readonly resizeTip: "Drag to resize · double-click to reset";
readonly transparent: "Transparent";
readonly exportTransparent: "The background is transparent, but this browser can’t make see-through video: the file shows black there.";
readonly exportSeeThrough: "See-through background";
// … 919 more lines
};Types
AlignEdge
typeWhere to line elements up.
type AlignEdge = 'left' | 'center' | 'right' | 'top' | 'middle' | 'bottom';AssistantTurn
typeOne exchange with the AI assistant (v0.4).
interface AssistantTurn {
id: number;
instruction: string;
reply: string;
/** Changes applied (one undo step), 0 when none. */
applied: number;
/** Why the changes weren't applied (a bad action, a failed request). */
error: string | null;
/**
* The project right after these changes (the editor's own copy): while it's still the current
* one, they're the latest step and can be undone from the turn.
*/
after?: Project;
/** Undone from the turn. */
undone?: boolean;
}AudioLibrary
typeA music & sound-effects source for the Audio panel — pass it as audioLibrary on <VideoEditor />. Every call gets an AbortSignal: the editor aborts when the user types on, switches category or closes the panel.
const library: AudioLibrary = {
categories: [{ id: 'chill', label: 'Chill' }],
search: async ({ text, category, cursor }, signal) => {
const res = await fetch(`/api/sounds?q=${text}&c=${category ?? ''}&page=${cursor ?? ''}`, { signal });
return res.json(); // { tracks: [...], next }
},
load: async (track, signal) => (await fetch(`/api/sounds/${track.id}/file`, { signal })).blob(),
};
<VideoEditor audioLibrary={library} />interface AudioLibrary {
/** Heading of the library section (default: the `audioLibrary` label, "Music & sounds"). */
title?: string;
/** Category chips; the editor puts "All" first. */
categories?: readonly AudioLibraryCategory[];
/** Search or browse (`text` empty). Called again for "Show more" with the page's cursor. */
search(query: AudioLibraryQuery, signal: AbortSignal): Promise<AudioLibraryPage>;
/** The full audio file to add to the project (any format the editor imports). */
load(track: AudioLibraryTrack, signal: AbortSignal): Promise<Blob>;
/** One line under the list, e.g. "Music by Example Audio · free for any use". */
notice?: string;
}A category chip of an AudioLibrary (e.g. "Upbeat", "Whooshes").
interface AudioLibraryCategory {
id: string;
/** Visible, already translated. */
label: string;
}AudioLibraryPage
typeOne page of results.
interface AudioLibraryPage {
tracks: readonly AudioLibraryTrack[];
/** Cursor for the next page; missing / null when there are no more. */
next?: string | null;
}What the user is looking for.
interface AudioLibraryQuery {
/** The search box text, trimmed (empty = browse). */
text: string;
/** The chosen category id, or null for "All". */
category: string | null;
/** Null for the first page; then the `next` cursor of the previous page ("Show more"). */
cursor: string | null;
}One sound in an AudioLibrary.
interface AudioLibraryTrack {
/** Stable id within the library. */
id: string;
/** Shown on the row and used as the clip's name. */
title: string;
/** Artist or creator, shown under the title. */
artist?: string;
/** Length in seconds, shown on the row. */
duration?: number;
/** `music` (default) or a short `sound` effect: picks the row's icon and spoken description. */
kind?: 'music' | 'sound';
/**
* A short, browser-playable preview (MP3 / AAC / Opus / WAV URL) played when the user taps ▶.
* Without it the editor previews the full file from {@link AudioLibrary.load}.
*/
previewUrl?: string;
/**
* Licence / attribution line, e.g. `"Song — Artist · CC BY 4.0"`. Shown on the row and kept with
* the media in the project (`Asset.credit`) so the host can credit it on publish.
*/
credit?: string;
}interface ControllerOptions {
labels: Labels;
backend?: 'auto' | 'webgpu' | 'webgl2';
/** Called (debounced) after edits with the current project — the host's durable save. */
onSave?: (project: Project) => void | Promise<void>;
/** Called when an export finishes. */
onExport?: (result: ExportResult) => void;
/** Called when a sound-only export finishes. */
onExportAudio?: (result: AudioExportResult) => void;
/** Called when a frame is saved as a picture. */
onSaveFrame?: (image: FrameImage) => void;
/** Gets media bytes for assets the host stores itself (`url` sources or its own keys). */
resolveMedia?: (asset: Asset) => Promise<Blob | null>;
/** Keep a local autosave + crash-recovery copy in the browser (default true). */
autosave?: boolean;
/** Base URL of the 3D sticker art (self-host it), or `false` to hide 3D stickers. */
stickerLibrary?: string | false;
/**
* Where animated emoji stickers come from (Noto Emoji Animation, CC BY 4.0): a base URL whose
* `<code>/512.webp` files are the animations, or `false` to hide the Animated tab. Default:
* Google's public copy. Placed stickers are stored in the project.
*/
animatedStickerLibrary?: string | false;
/**
* Lighter copies of heavy videos for smooth editing (v0.4): `auto` (default) makes them for
* videos this device would struggle with (4K; 1080p on budget phones), `always` for every
* video over 540p, `off` never. Previews use the copy; exports always use the original.
*/
proxies?: 'auto' | 'always' | 'off';
/** The host's music & sound-effects source for the Audio panel. */
audioLibrary?: AudioLibrary;
/** Turns speech into timed words for auto captions (on-device or the host's service). */
transcriber?: Transcriber;
/** Host customisation: hidden tools, own panels, buttons and media sources (embed.ts). */
customize?: EditorCustomization;
/** Removes photo backgrounds (`createBackgroundRemover()` from `@video-ultra/ai`, or yours). */
backgroundRemover?: BackgroundRemover;
/** AI editing with the host's model (`createChatAssistant()` from `@video-ultra/ai`, or yours). */
assistant?: EditingAssistant;
/** Text to speech (`createSpeechEndpoint()` from `@video-ultra/ai`, or yours). */
speech?: SpeechGenerator;
}CustomButton
typeA top-bar button the host adds.
interface CustomButton {
id: string;
label: string;
icon?: CustomIconPath;
/** `secondary` (default) or `primary`. */
variant?: 'primary' | 'secondary';
onClick: (controller: EditorController) => void;
}CustomIconPath
typeAn icon: the d of one SVG path on a 24 × 24 grid, drawn as a 1.75-px stroke.
type CustomIconPath = string;CustomPanel
typeA panel the host adds.
interface CustomPanel {
id: string;
/** Visible, already translated. */
label: string;
icon: CustomIconPath;
tip?: string;
/** The panel's content. It can use the controller to edit the project. */
render: (controller: EditorController) => ReactNode;
}The embedding API (v0.3): what a host app can change about the editor without forking it — hide or reorder built-in tools, add its own panels and top-bar buttons, bring its own media (stock footage, a team library), and listen to what happens. Custom text is labels.
<VideoEditor
customize={{
hide: ['captions', 'blur'],
railOrder: ['media', 'brand', 'text'],
panels: [{ id: 'brand', label: 'Brand', icon: 'M4 4h16v16H4z', render: (ctl) => <BrandKit ctl={ctl} /> }],
buttons: [{ id: 'share', label: 'Share', onClick: (ctl) => share(ctl.project) }],
mediaSources: [stockFootage],
}}
onEvent={(e) => analytics.track(e.type)}
/>interface EditorCustomization {
/**
* Built-in things to hide, by id: left-menu panels (`'templates'`, `'text'`, `'captions'`,
* `'audio'`, `'stickers'`, `'filters'`, `'transitions'`, `'blur'`), phone / inspector tools
* (`'speed'`, `'mask'`, `'key'`, `'cutout'`, …), commands (`'duplicate'`, `'copy'`, …) and the
* top bar's "Your videos" (`'videos'`; hosts that keep their own project list).
*/
hide?: readonly string[];
/** The left menu's order, by panel id (built-in and custom); the rest follow in their order. */
railOrder?: readonly string[];
/** The host's own panels in the left menu (and the phone's add tools). */
panels?: readonly CustomPanel[];
/** The host's own buttons in the top bar, before Export. */
buttons?: readonly CustomButton[];
/** The host's media in the Media panel: search, ▶ thumbnails, Add (stored in the project). */
mediaSources?: readonly MediaSource[];
}EditorEvent
typeSomething that happened in the editor (onEvent on <VideoEditor />, or controller.on).
type EditorEvent = {
type: 'change';
label: string | null;
} | {
type: 'selection';
ids: readonly string[];
} | {
type: 'playback';
playing: boolean;
} | {
type: 'command';
id: string;
} | {
type: 'import';
assetId: string;
name: string;
} | {
type: 'export';
phase: 'start' | 'done' | 'cancelled' | 'error';
} | {
type: 'panel';
id: string | null;
};ImportRow
typeinterface ImportRow {
id: string;
name: string;
status: 'working' | 'error';
message?: string;
}Labels
typeAll labels. Override any subset through the labels prop.
type Labels = {
-readonly [K in keyof typeof DEFAULT_LABELS]: (typeof DEFAULT_LABELS)[K] extends (...args: infer A) => string ? (...args: A) => string : (typeof DEFAULT_LABELS)[K] extends string ? string : (typeof DEFAULT_LABELS)[K];
};LayoutMode
typeWhich layout the editor is in (from the root's width; CSS uses container queries too).
type LayoutMode = 'phone' | 'tablet' | 'desktop';LookItem
typeVisual items that have a look (filter, adjustments, crop).
type LookItem = Extract<Item, {
filter: unknown;
}>;MediaSource
typeA media source for the Media panel (stock footage, the host's library). Every call gets an AbortSignal: the editor aborts when the user types on or closes the panel.
interface MediaSource {
id: string;
/** Visible, already translated (the panel's section heading). */
label: string;
/** Results for the search box text (empty = browse); `cursor` from the last page's `next`. */
search(query: {
text: string;
cursor: string | null;
}, signal: AbortSignal): Promise<{
items: readonly MediaSourceItem[];
next?: string | null;
}>;
/** The file for a result the user adds. */
load(item: MediaSourceItem, signal: AbortSignal): Promise<Blob>;
}MediaSourceItem
typeOne result of a MediaSource.
interface MediaSourceItem {
id: string;
name: string;
kind: 'video' | 'image' | 'audio';
/** A small picture for the grid (any image URL). */
thumbnailUrl?: string;
/** Seconds (video / audio), shown on the tile. */
duration?: number;
/** Licence / attribution line, kept with the media in the project (`Asset.credit`). */
credit?: string;
}PanelId
typeAdd-content categories (rail on desktop, add tools on phones).
type PanelId = 'media' | 'text' | 'audio' | 'stickers' | 'canvas' | 'filters' | 'transitions' | 'layers'
/** Every step since the project opened; tap one to go back to it. */
| 'history' | 'captions'
/** Blurred / pixelated areas (v0.2 C3). */
| 'blur'
/** Templates (v0.3). */
| 'templates'
/** AI editing with the host's assistant (v0.4). */
| 'assistant'
/** A host's own panel (embedding API, v0.3). */
| `custom:${string}`;Visible text of the starter set (titles and categories); override to translate.
interface StarterSoundLabels {
title: string;
credit: string;
transitions: string;
interface: string;
impacts: string;
whoosh: string;
swoosh: string;
riser: string;
click: string;
pop: string;
tick: string;
ding: string;
success: string;
error: string;
boom: string;
thud: string;
}Targets
typeinterface Targets {
/** The selected item, or the main clip under the playhead. */
subject: Item | null;
/** Split / freeze act on this item at the playhead. */
split: {
item: Item | null;
reason: string | null;
};
freeze: {
item: Item | null;
reason: string | null;
};
/** Delete / duplicate act on the selection only. */
selection: {
item: Item | null;
reason: string | null;
};
/**
* Filters and adjustments: the selected picture; else the main clip under the playhead (or the
* first one).
*/
look: LookItem | null;
/** Set when the selection can't take a filter, so the panel says why it shows another clip. */
lookNote: string | null;
/**
* Transitions: the clip after the cut. The selected picture's own cut (main track, or touching
* pictures on its layer); else the main-track cut nearest the playhead.
*/
transition: Item | null;
/** Why there is no transition target (or why it's not the selection's). */
transitionNote: string | null;
/**
* A selected element that moves in and out instead (text, sticker, or a layer picture with no
* clip touching it): the Transitions panel shows its entrance / exit.
*/
motion: Item | null;
hasClips: boolean;
}ThemeMode
typedark (default), light, or auto to follow the OS setting.
type ThemeMode = 'dark' | 'light' | 'auto';ThemeOverrides
typeTyped shortcuts for the most common CSS variables. Anything else can be overridden in CSS: .vu-root { --vu-surface-1: #000; } — see the Theming docs for every token.
interface ThemeOverrides {
accent?: string;
accentHover?: string;
accentContrast?: string;
/** Accent-coloured text and icons on surfaces (e.g. selected tool label). Defaults to `accent`. */
accentText?: string;
bg?: string;
stage?: string;
surface1?: string;
surface2?: string;
surface3?: string;
text?: string;
textMuted?: string;
border?: string;
fontFamily?: string;
/** Base control radius, e.g. `'10px'`. Small and large radii scale from it. */
radius?: string;
/** Background of the timeline area. */
timelineBg?: string;
}Toast
typeinterface Toast {
id: number;
message: string;
tone: 'info' | 'error' | 'success';
/** One follow-up, e.g. Undo. */
action?: {
label: string;
run: () => void;
};
}ToolId
typeTools whose controls open in the sheet (phone/tablet) or the inspector (desktop).
type ToolId = 'speed' | 'volume' | 'fade' | 'filter' | 'adjust' | 'crop' | 'transform' | 'transition' | 'text-edit' | 'text-style' | 'opacity' | 'duration' | 'animate' | 'arrange' | 'canvas' | 'add-text' | 'add-sticker' | 'add-audio' | 'add-media' | 'key' | 'blend' | 'region' | 'mask' | 'cutout' | 'keyframes' | 'protrim' | 'scenes' | 'soundfx' | 'readaloud';UiState
typeUI-only state (selection, panels, playback flag). The project lives in the core editor store.
interface UiState {
/** `stopped`: the engine died mid-session (the project is safe; reload to continue). */
status: 'loading' | 'ready' | 'unsupported' | 'error' | 'stopped';
statusMessage: string | null;
layout: LayoutMode;
/** The selected item the tools act on (the last one picked). */
selectedId: string | null;
/**
* Everything selected, `selectedId` included (several after Shift-click, Select all, or picking
* a group). Empty when nothing is selected.
*/
selectedIds: readonly string[];
/**
* Combined clips opened for editing, outermost first: the timeline, stage and
* inspector show the innermost one's inside. `outerTime`: the playhead before it opened.
*/
inside: readonly {
assetId: string;
itemId: string;
name: string;
outerTime: number;
}[];
/** "Your videos" popover (top bar). */
videosOpen: boolean;
/** Layers panel: tapping rows adds to the selection (phones have no Shift key). */
layersSelecting: boolean;
/** The context menu, at a point in the editor root (px). */
menu: {
x: number;
y: number;
} | null;
/** Auto captions running: what it's doing and how far (null = not running). */
captionJob: {
stage: 'listen' | 'download' | 'transcribe';
fraction: number;
loaded?: number;
total?: number;
} | null;
/** Background removal running (v0.3): for which item, what it's doing, how far. */
cutoutJob: {
itemId: string;
stage: 'download' | 'work';
fraction: number;
} | null;
/** Bumped when a sticker's "has a background to remove" check finishes (re-shows the tools). */
stickerChecks: number;
/** Scene detection running (v0.4): on which clip, how far. */
sceneJob: {
itemId: string;
fraction: number;
} | null;
/** AI editing (v0.4): this session's conversation, and whether a request is out. */
assistantTurns: AssistantTurn[];
assistantBusy: boolean;
/** Text to speech (v0.4) is generating. */
speechBusy: boolean;
/** Proxies being made (v0.4): asset id → 0…1. */
proxyJobs: Record<string, number>;
/** A caption whose text box should take focus in the Captions panel. */
captionEditing: string | null;
/** Last screen-reader announcement (a polite live region reads it). */
announcement: string;
panel: PanelId | null;
tool: ToolId | null;
/** Phone/tablet: the add panel is open in the sheet. */
sheetPanel: boolean;
playing: boolean;
/** Timeline zoom: pixels per second. */
pxPerSecond: number;
imports: ImportRow[];
toasts: Toast[];
exportOpen: boolean;
helpOpen: boolean;
/** Only the video and play controls (works everywhere, incl. iPhone). */
previewMode: boolean;
save: 'idle' | 'saving' | 'saved';
/** This project is open (and saving) in another tab: this one doesn't save until it takes over. */
readOnly: boolean;
/** Media files that couldn't be opened, in project order: the banner asks or re-links them. */
mediaProblems: MediaProblem[];
persistent: boolean | null;
recording: boolean;
/** Voiceover: 3, 2, 1 shown on the video before recording starts; null otherwise. */
countdown: number | null;
/** The camera recorder covers the editor (v0.2 D. Capture & export). */
cameraOpen: boolean;
/** Green screen "pick from video": the next tap on the stage picks this item's key colour. */
picking: string | null;
}VideoEditorProps
typeProps of VideoEditor.
interface VideoEditorProps {
/** Project to open (object or JSON string). Without it the last autosaved project reopens, or a new one starts. */
initialProject?: Project | string | undefined;
/** Called about a second after each edit with the current project. This is the durable save — store it. */
onSave?: ((project: Project) => void | Promise<void>) | undefined;
/** Called when an export finishes, with the video file. */
onExport?: ((result: ExportResult) => void) | undefined;
/** Called when a sound-only export finishes, with the sound file. */
onExportAudio?: ((result: AudioExportResult) => void) | undefined;
/** Called when a frame is saved as a picture, with the image file. */
onSaveFrame?: ((image: FrameImage) => void) | undefined;
/** Shows a close button that calls this. */
onClose?: (() => void) | undefined;
/** Called when the device can't run the editor (instead of, or as well as, the built-in message). */
onUnsupported?: ((capabilities: Capabilities) => void) | undefined;
/** Gets bytes for media the host stores itself (assets with `url` sources). */
resolveMedia?: ((asset: Asset) => Promise<Blob | null>) | undefined;
/** Keep a local autosave and crash-recovery copy in the browser (default true). */
autosave?: boolean | undefined;
/**
* Where the 3D sticker images come from: a base URL (self-host the MIT-licensed set), or `false`
* to offer only emoji, shapes and uploads. Default: a pinned public CDN. Placed stickers are
* stored in the project, so exports never depend on it.
*/
stickerLibrary?: string | false | undefined;
/**
* Where animated emoji stickers come from (Noto Emoji Animation, CC BY 4.0): a base URL whose
* `<code>/512.webp` files are the animations (and `<code>/emoji.svg` stills for the panel's
* tiles, optional), or `false` to hide the Animated tab. Default:
* Google's public copy. Placed stickers are stored in the project.
*/
animatedStickerLibrary?: string | false | undefined;
/**
* Lighter copies of heavy videos for smooth editing, kept on this device: `auto` (default)
* for videos this device would struggle with (4K; 1080p on budget phones), `always` for every
* video over 540p, `off` never. Previews use the copy; exports always use the original.
*/
proxies?: 'auto' | 'always' | 'off' | undefined;
/**
* A music & sound-effects source for the Audio panel: search, categories, a ▶ preview and the
* licence line per sound, and Add (at the playhead). The picked file is stored in the project
* like an import (its licence line on the asset as `credit`), so exports never depend on the
* source. Without it the Audio panel offers the user's own files and voiceover only — the
* editor ships no catalogue. `createStarterSounds()` is a small built-in set of synthesised,
* CC0 sound effects. Read once, like `initialProject`.
*/
audioLibrary?: AudioLibrary | undefined;
/**
* Turns speech into timed words for Auto captions: `createOnDeviceTranscriber()` from the
* optional `@video-ultra/captions` package (English, on the device, nothing uploaded), or your
* own service for any language. Without it, captions can still be imported (.srt / .vtt) or
* typed.
*/
transcriber?: Transcriber | undefined;
/**
* Removes photo backgrounds: `createBackgroundRemover()` from the optional `@video-ultra/ai`
* package (runs on the device, nothing uploaded), or your own service. Without it the option
* isn't shown.
*/
backgroundRemover?: BackgroundRemover | undefined;
/**
* AI editing (v0.4): an Assistant panel where people type what they want ("make it warmer",
* "add a title at the start") and your model's answer is applied as one undo step. Use
* `createChatAssistant({ endpoint })` from `@video-ultra/ai` with your own server, or implement
* `EditingAssistant`. A description of the project (no media) is sent to it. Without it the
* panel isn't shown.
*/
assistant?: EditingAssistant | undefined;
/**
* Text to speech (v0.4): "Text to speech" in the Audio panel and "Read aloud" on texts add a
* spoken sound clip. Use `createSpeechEndpoint({ endpoint })` from `@video-ultra/ai` with
* your own server, or implement `SpeechGenerator`. Without it these aren't shown.
*/
speech?: SpeechGenerator | undefined;
/**
* Embedding API: hide or reorder built-in tools, add your own panels, top-bar buttons and
* media sources (see {@link EditorCustomization}).
*/
customize?: EditorCustomization | undefined;
/** Everything that happens in the editor (edits, selection, playback, commands, export…). */
onEvent?: ((event: EditorEvent) => void) | undefined;
/** `dark` (default), `light` or `auto` (follow the OS). */
theme?: ThemeMode | undefined;
/** Typed overrides for the common theme tokens. */
themeOverrides?: ThemeOverrides | undefined;
/**
* `normal` (default), `high` (stronger text, borders and focus rings — for low vision or bright
* sunlight), or `auto` (high when the OS asks for more contrast).
*/
contrast?: 'normal' | 'high' | 'auto' | undefined;
/**
* Control sizes: `auto` (default — thumb-sized on touch screens), `touch` (thumb-sized
* everywhere) or `compact` (mouse sizes, also on touch screens).
*/
density?: 'auto' | 'touch' | 'compact' | undefined;
/** Replace any of the editor's text (translation). */
labels?: Partial<Labels> | undefined;
/** Text direction of the editor chrome. The timeline always runs left to right. */
dir?: 'ltr' | 'rtl' | undefined;
/** Called once the editor is ready, with its controller (programmatic control: play, seek, edits). */
onReady?: ((controller: EditorController) => void) | undefined;
/** Force a renderer (testing). Default: WebGPU when available, else WebGL2. */
backend?: 'auto' | 'webgpu' | 'webgl2' | undefined;
className?: string | undefined;
style?: CSSProperties | undefined;
}