@diffusionstudio/core-v4
Version:
2D motion graphics and video rendering engine
178 lines (177 loc) • 6 kB
TypeScript
import { Timestamp } from '../models';
import { Clip, ClipType } from '../clips';
import { Serializer } from '../services';
import { Renderer } from '../renderer';
import { Composition } from '../composition';
import { InsertMode, LayerIndex } from './types';
import { Size, Time } from '../types';
import { BaseSource } from '../sources';
type Events = {
frame: number | undefined;
attach: undefined;
detach: undefined;
update: any;
};
declare const Layer_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;
frame?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<number | undefined, 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;
update?: {
[x: string]: (event: import('../mixins/event/types').EmittedEvent<any, any>) => void;
} | undefined;
};
on<T extends "*" | "error" | keyof Events>(eventType: T, callback: (event: import('../mixins/event/types').EmittedEvent<import('../mixins/event/types').BaseEvents<Events>[T], /*elided*/ any>) => void): string;
off(id?: string | "*", ...ids: string[]): void;
emit<T extends "*" | "error" | keyof Events>(eventType: T, detail: import('../mixins/event/types').BaseEvents<Events>[T]): void;
bubble(target: /*elided*/ any): string;
resolve(eventType: "*" | "error" | keyof Events): (resolve: (value: unknown) => void, reject: (reason?: any) => void) => void;
};
} & typeof Serializer;
export declare class Layer<Clp extends Clip = Clip> extends Layer_base {
/**
* Unique identifier of the object
*/
id: string;
/**
* Data associated with the layer
*/
data: Record<string, unknown>;
/**
* Flag to check if the layer is the primary layer
*/
primary: boolean;
/**
* 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;
/**
* Connect the layer with the composition
*/
connect(composition: Composition): this | Promise<this>;
/**
* Controls how the clips should be inserted and updated
*/
get mode(): InsertMode;
set mode(value: InsertMode);
/**
* Change the index of the layer
*/
index(layer: LayerIndex): this;
/**
* 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>;
/**
* Move all clips of the layer at once along the timeline
*/
offset(time: Time): this;
/**
* 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>;
/**
* Remove a given clip from the layer. Calls update after removing the clip.
* @returns `Layer` when it has been successfully removed `undefined` otherwise
*/
remove<L extends Clp>(clip: L): L | undefined;
sequential(value?: boolean): this;
/**
* Get the first visible frame of the clip
*/
get stop(): Timestamp;
/**
* Get the last visible frame of the clip
*/
get start(): Timestamp;
/**
* 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;
_resetInternalState(): 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 sources The sources to use for the restoration
* @returns The restored layer
*/
restoreCheckpoint(checkpoint: unknown, sources?: BaseSource[]): Promise<this>;
}
export {};