@diffusionstudio/core-v4
Version:
2D motion graphics and video rendering engine
237 lines (236 loc) • 8.66 kB
TypeScript
import { Timestamp, Transcript } from '../models';
import { Serializer } from '../services';
import { Renderer } from '../renderer';
import { Layer } from '../layer';
import { AudioClip, Clip, TextClip } from '../clips';
import { Time } from '../types';
import { Markers, CompositionEvents, CompositionSettings, PlaybackEndBehavior, ScreenshotImageFormat } from './types';
import { CaptionPreset } from '../captions';
import { BaseSource } from '../sources';
declare const Composition_base: {
new (...args: any[]): {
_handlers: {
'*'?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<any, any>) => void;
} | undefined;
error?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<Error, any>) => void;
} | undefined;
play?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<import('..').frame, any>) => void;
} | undefined;
pause?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<import('..').frame, any>) => void;
} | undefined;
attach?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
detach?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
resize?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
mount?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
unmount?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
frame?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<number | undefined, any>) => void;
} | undefined;
currentframe?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<import('..').frame, any>) => void;
} | undefined;
init?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
update?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<any, any>) => void;
} | undefined;
load?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<undefined, any>) => void;
} | undefined;
};
on<T extends "*" | "error" | keyof CompositionEvents>(eventType: T, callback: (event: import('../mixins/event/types').EmittedEvent<import('../mixins/event/types').BaseEvents<CompositionEvents>[T], /*elided*/ any>) => void): string;
off(id?: string | "*", ...ids: string[]): void;
emit<T extends "*" | "error" | keyof CompositionEvents>(eventType: T, detail: import('../mixins/event/types').BaseEvents<CompositionEvents>[T]): void;
bubble(target: /*elided*/ any): string;
resolve(eventType: "*" | "error" | keyof CompositionEvents): (resolve: (value: unknown) => void, reject: (reason?: any) => void) => void;
};
} & typeof Serializer;
export declare class Composition extends Composition_base {
/**
* 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, }?: CompositionSettings);
/**
* Settings of the composition
*/
get settings(): Required<CompositionSettings>;
set settings(settings: Required<CompositionSettings>);
/**
* 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 stops playing
*/
get duration(): Timestamp;
/**
* Limit the total duration of the composition
*/
set duration(time: Time | undefined);
/**
* Get the currently rendered time of the playback
*/
get playhead(): Timestamp;
/**
* Set the currently rendered time of the playback
*/
set playhead(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;
/**
* Insert a new layer at the specified index (defaults to 0)
* @param Layer The layer to insert
* @param index The index to insert at (0 = top layer, default: 0)
*/
insertLayer<L extends Layer>(layer: L, index?: number): Promise<L>;
/**
* Create a layer with the given type
* @param type the desired type of the layer
* @returns A new layer
*/
createLayer<L extends Clip>(index?: number): Layer<L>;
/**
* Create captions for the composition
* @param source The source to create captions for
* @param strategy The strategy to use for creating captions
* @returns A new layer with captions
*/
createCaptions(source: AudioClip | Transcript, strategy?: CaptionPreset | (new () => CaptionPreset), layer?: Layer<TextClip>): Promise<Layer<TextClip>>;
/**
* Convenience function for appending a layer
* aswell as the clip to the composition
*/
add<L extends Clip | Clip[]>(clip: L): Promise<L>;
/**
* Remove a given clip from the composition
* @returns `Clip` when it has been successfully removed `undefined` otherwise
*/
remove<L extends Clip>(clip: L): L | undefined;
/**
* 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
*/
removeLayer(layer: Layer): Layer | undefined;
/**
* Remove multiple layers from the composition
* @returns `Layer[]` all removed layers
*/
removeLayers(...layers: Layer[]): Layer[];
/**
* 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, sources?: BaseSource[]): Promise<this>;
}
export {};