@diffusionstudio/core-v4
Version:
A fast, browser based video compositing engine powered by WebCodecs
149 lines (148 loc) • 4.8 kB
TypeScript
import { Clip, ClipType } from '../clips';
import { Serializer } from '../services';
import { Asset, Size } from '../types';
import { Renderer } from '../renderer';
import { Composition } from '../composition';
import { InsertMode, LayerIndex } from './types';
import { LayerOptions } from './interfaces';
export declare class Layer<Clp extends Clip = Clip> extends Serializer {
/**
* Unique identifier of the object
*/
id: string;
/**
* Data associated with the layer
*/
data: Record<string, unknown>;
/**
* Controls the visability of the layer
*/
disabled: boolean;
/**
* The clips to be displayed
*/
clips: Clp[];
/**
* Reference to the composition
*/
composition?: Composition;
/**
* Timestamp when the layer has been created
*/
readonly createdAt: Date;
/**
* Id of the clips in the layer
*/
get type(): ClipType;
/**
* The index of the clip that should be rendered
*/
private currentMainClipIndex;
/**
* Tracks the clips that are currently visible. In the case of transitions, this can be more than one clip at a time.
*/
private visibleClips;
/**
* Controls how the clips should be inserted and updated
*/
private strategy;
constructor(options?: LayerOptions);
/**
* Initialize after the composition has been defined
*/
init(composition: Composition): Promise<void>;
/**
* Controls how the clips should be inserted and updated
*/
get mode(): InsertMode;
set mode(value: InsertMode);
/**
* Get or set the index of the layer
*/
get index(): number;
set index(index: LayerIndex);
/**
* Seek the provided time if the layer contains
* audio or video clips. Will await the promise
* otherwise will resolve immediately
*/
seek(renderer: Renderer): Promise<void>;
/**
* Seek the provided time if the layer contains
* audio or video clips. Will await the promise
* otherwise will resolve immediately
*/
play(renderer: Renderer): Promise<void>;
/**
* Seek the provided time if the layer contains
* audio or video clips. Will await the promise
* otherwise will resolve immediately
*/
pause(renderer: Renderer): Promise<void>;
/**
* Triggered when the layer is redrawn, manages
* the clip's lifecycle
*/
update(renderer: Renderer): Promise<void>;
render(renderer: Renderer): void;
/**
* Adds a new clip to the layer. Calls update after adding the clip.
* @param clip The clip to add
* @param index The index to insert the clip at, will be ignored if layer is not stacked
* @throws Error if the clip can't be added
*/
add<L extends Clp>(clip: L, index?: number): Promise<L>;
/**
* Verify that the clip can be moved within the layer. If not, create a new layer and add the clip to that.
* @param clip The clip to verify
*/
verifyUpdate(clip: Clp): void;
/**
* Remove the clip from the layer (if it exists) and add it to a new layer
* @param clip The clip to relocate
* @param layer The layer to add the clip to, if not provided the clip will be added to the current layer
* @param index The index to add the clip at, will be ignored if layer is not stacked
* @throws Error if the clip can't be added
*/
relocate(clip: Clp, layer?: Layer, index?: number): void;
/**
* Remove a given clip from the layer. Calls update after removing the clip.
* @param clip The clip to remove
* @param detachEmptyLayer Whether to detach the layer if it is empty
* @returns `Layer` when it has been successfully removed `undefined` otherwise
*/
remove<L extends Clp>(clip: L, detachEmptyLayer?: boolean): L | undefined;
sequential(value?: boolean): this;
/**
* Get the last visible frame of the layer
*/
get end(): number;
/**
* Get the first visible frame of the layer
*/
get start(): number;
/**
* Remove the layer from the composition
*/
detach(): this;
/**
* Triggered when the composition is resized
*/
layout(prevLayout: Size): void;
/**
* Remove all clips from the layer
*/
clear(): void;
/**
* Create a checkpoint of the layer. May include Blobs.
* @returns A serialized representation of the layer
*/
createCheckpoint(): Promise<unknown>;
/**
* Restore a checkpoint of the layer.
* @param checkpoint The checkpoint to restore
* @param assets The assets to use for the restoration
* @returns The restored layer
*/
restoreCheckpoint(checkpoint: unknown, assets: Asset[]): Promise<this>;
}