UNPKG

narraleaf-react

Version:

A React visual novel player framework

129 lines (128 loc) 5.67 kB
import type { CommonDisplayableConfig } from "../../types"; import { TransformDefinitions } from "./type"; import { CSSProps } from "../../elements/transition/type"; type OverwriteMap = { overwrite: CSSProps; }; export type OverwriteDefinition = { [K in keyof OverwriteMap]?: OverwriteHandler<OverwriteMap[K]>; }; type OverwriteHandler<T> = (value: Partial<TransformDefinitions.Types>) => T; export declare class Transform<T extends TransformDefinitions.Types = CommonDisplayableConfig> { /** * Apply transform immediately */ static immediate<T extends TransformDefinitions.Types>(props: TransformDefinitions.SequenceProps<T>): Transform<T>; /** * Go to the left side of the stage */ static left(duration: number, easing?: TransformDefinitions.EasingDefinition): Transform<TransformDefinitions.ImageTransformProps>; /** * Go to the right side of the stage */ static right(duration: number, easing?: TransformDefinitions.EasingDefinition): Transform<TransformDefinitions.ImageTransformProps>; /** * Go to the center of the stage */ static center(duration: number, easing?: TransformDefinitions.EasingDefinition): Transform<TransformDefinitions.ImageTransformProps>; /** * Create a new transform with the given config. The sequences will be empty. * @param config - The config for the transform. * @returns A new transform with the given config. */ static create<T extends TransformDefinitions.Types = CommonDisplayableConfig>(config?: Partial<TransformDefinitions.TransformConfig>): Transform<T>; /** * @example * ```ts * const transform = new Transform<ImageTransformProps>({ * opacity: 1, * position: "center" * }, { * duration: 0, * ease: "linear" * }); * ``` */ constructor(sequences: TransformDefinitions.Sequence<T>[], transformConfig?: Partial<TransformDefinitions.TransformConfig>); constructor(props: TransformDefinitions.SequenceProps<T>, options?: Partial<TransformDefinitions.CommonTransformProps>); /** * Create a new transform that repeats {@link n} x current repeat count times. * @example * ```ts * transform * .repeat(2) * .repeat(3) * // repeat 6 times * ``` */ repeat(n: number): Transform<T>; /** * Copy the current transform. * @returns {Transform<T>} A new transform with the same sequences and config. */ copy(): Transform<T>; /** * Commits all staged changes to the transform sequence. * This method will create a new sequence from all pending changes that have been staged via chained methods. * If there are no staged changes, this method will return the current instance without modification. * After committing, the staged changes array will be cleared. * @returns {this} The current Transform i nstance for method chaining * @example * ```ts * transform * .position({ x: 100, y: 100 }) * .opacity(1).commit() // will create a new sequence with opacity 1 and position x: 100, y: 100 * .position({ x: 200, y: 200 }) * .opacity(0).commit({ duration: 1000 }) // will create a new sequence with opacity 0 and position x: 200, y: 200 with a duration of 1 second * ``` * * **Note**: The staged changes will be committed before animation starts to ensure the latest changes are applied. */ commit(options?: Partial<TransformDefinitions.SequenceOptions>): this; /** * Set the zoom of the current staging sequence. * @param zoom - The zoom of the transform. use `1` to keep the original size */ zoom(zoom: TransformDefinitions.Types["zoom"]): this; /** * Set the scale of the current staging sequence on x axis. * @param scaleX - The scale of the transform on x axis. */ scaleX(scaleX: TransformDefinitions.Types["scaleX"]): this; /** * Set the scale of the current staging sequence on y axis. * @param scaleY - The scale of the transform on y axis. */ scaleY(scaleY: TransformDefinitions.Types["scaleY"]): this; /** * Set the scale of the current staging sequence. * @param scaleX - The scale of the transform on x axis. use negative value to invert the scale * @param scaleY - The scale of the transform on y axis. use negative value to invert the scale */ scale(scaleX: TransformDefinitions.Types["scaleX"], scaleY: TransformDefinitions.Types["scaleY"]): this; /** * Rotate the current staging sequence. * @param {number} rotation - The rotation of the transform. * @returns {this} The current Transform instance for method chaining. */ rotation(rotation: TransformDefinitions.Types["rotation"]): this; /** * Set the position of the current staging sequence. * @param {number} position - The position of the transform. * @returns {this} The current Transform instance for method chaining. */ position(position: TransformDefinitions.Types["position"]): this; /** * Set the opacity of the current staging sequence. * @param {number} opacity - The opacity of the transform. * @returns {this} The current Transform instance for method chaining. */ opacity(opacity: TransformDefinitions.Types["opacity"]): this; /** * Set the font color of the current staging sequence. * @param {string} fontColor - The font color of the transform. * @returns {this} The current Transform instance for method chaining. */ fontColor(fontColor: TransformDefinitions.Types["fontColor"]): this; } export {};