UNPKG

@diffusionstudio/core-v4

Version:

A fast, browser based video compositing engine powered by WebCodecs

221 lines (220 loc) 6.86 kB
import { Serializer } from '../services'; import { Renderer } from '../renderer'; import { Layer } from '../layer'; import { Clip } from '../clips'; import { Asset, Time } from '../types'; import { Markers, CompositionEvents, CompositionSettings, PlaybackEndBehavior, ScreenshotImageFormat } from './types'; declare const Composition_base: { new (...args: any[]): { _handlers: { 'playback:start'?: { callback: (event: undefined) => void; once?: boolean; }[] | undefined; 'playback:end'?: { callback: (event: undefined) => void; once?: boolean; }[] | undefined; 'playback:time'?: { callback: (event: number | undefined) => void; once?: boolean; }[] | undefined; 'layer:add'?: { callback: (event: undefined) => void; once?: boolean; }[] | undefined; 'layer:remove'?: { callback: (event: undefined) => void; once?: boolean; }[] | undefined; resize?: { callback: (event: undefined) => void; once?: boolean; }[] | undefined; restored?: { callback: (event: undefined) => void; once?: boolean; }[] | undefined; }; _regexHandlers: { pattern: RegExp; callback: (event: { type: any; detail: any; }) => void; once?: boolean; }[]; on<K extends keyof CompositionEvents>(eventType: RegExp, callback: (event: { type: K; detail: CompositionEvents[K]; }) => void, options?: { once?: boolean; }): () => void; on<K extends keyof CompositionEvents>(eventType: K, callback: (event: CompositionEvents[K]) => void, options?: { once?: boolean; }): () => void; off<K extends keyof CompositionEvents>(handle: RegExp | (() => void) | (() => void)[] | K, callback?: ((event: CompositionEvents[K]) => void) | undefined): void; offAny(): void; emit<K extends keyof CompositionEvents>(eventType: K, detail: CompositionEvents[K]): void; }; } & typeof Serializer; export declare class Composition extends Composition_base { /** * Defines the last set time of the playhead */ private _playheadTime; /** * Unique identifier of the composition */ id: string; /** * Access the renderer */ renderer: Renderer; /** * Layers attached to the composition */ layers: Layer[]; /** * Defines special timestamps of the composition */ markers: Markers; /** * Timestamp when the composition has been created */ readonly createdAt: Date; /** * Data associated with the clip */ data: Record<string, unknown>; /** * Behavior when playback reaches the end of the composition */ playbackEndBehavior: PlaybackEndBehavior; constructor({ height, width, background, playbackEndBehavior, licenseKey, }?: CompositionSettings & { licenseKey?: string | null; }); /** * Settings of the composition */ get settings(): Required<CompositionSettings>; set settings(settings: Required<CompositionSettings>); /** * Time of the playhead, it's the playback time * when the composition is playing. Otherwise a fixed time. */ get playheadTime(): number; set playheadTime(time: Time); /** * Get the current playback state of the composition */ get playing(): boolean; /** * Get the current width of the canvas */ get width(): number; /** * Get the current height of the canvas */ get height(): number; /** * This is where the playback ends playing */ get duration(): number; /** * Get the last rendered time in **seconds** */ get currentTime(): number; /** * Set the time to be rendered in **seconds** */ set currentTime(time: Time); /** * Get all clips in the composition */ get clips(): Clip[]; /** * Resize the renderer */ resize(width: number, height: number): void; /** * Add the renderer to the dom. * This will start the ticker */ mount(element: HTMLElement): void; /** * Remove the renderer from the dom. * This will stop the ticker */ unmount(): void; /** * Adds a new layer to the composition at the specified index (defaults to 0) * @param Layer The layer to add * @param index The index to insert at (0 = top layer, default: 0) */ add<L extends Layer>(layer: L, index?: number): Promise<L>; /** * Create a empty layer synchronously * @returns A new layer */ createLayer<L extends Clip>(index?: number): Layer<L>; /** * Compute the currently active frame */ update(): Promise<void>; /** * Convenience function to take a screenshot of the current frame */ screenshot(format?: ScreenshotImageFormat, quality?: number): string; /** * Set the playback position to a specific time * @param time new playback time (defaults to 0) */ seek(time?: Time): Promise<void>; /** * Play the composition * @param time The time to start playing from */ play(time?: Time): Promise<void>; /** * Pause the composition */ pause(): Promise<void>; /** * Remove all layers and clips from the composition */ clear(): void; /** * Get the current playback time and composition * duration formatted as `00:00 / 00:00` by default. * if **hours** is set the format is `HH:mm:ss` whereas * **milliseconds** will return `mm:ss.SSS` */ time(precision?: { hours?: boolean; milliseconds?: boolean; }): string; /** * Remove a given layer from the composition * @returns `Layer` when it has been successfully removed `undefined` otherwise */ remove<L extends Layer>(layers: L | L[]): L[]; /** * Handle the playback end behavior */ private handlePlaybackEnd; /** * Create a checkpoint of the composition. May include Blobs. * @returns A serialized representation of the composition */ createCheckpoint(): Promise<unknown>; /** * Restore a checkpoint of the composition. * @param checkpoint The checkpoint to restore * @param sources The sources to use for the restoration * @returns The restored composition */ restoreCheckpoint(checkpoint: unknown, assets: Asset[]): Promise<this>; toString(): string; } export {};