narraleaf-react
Version:
A React visual novel player framework
120 lines (119 loc) • 5.34 kB
TypeScript
import React from "react";
import type { CommonDisplayableConfig } from "../../types";
import type { DOMKeyframesDefinition } from "motion";
import { TransformDefinitions } from "./type";
import { CSSProps } from "../../elements/transition/type";
export type Transformers = "position" | "opacity" | "scale" | "rotation" | "display" | "src" | "backgroundColor" | "backgroundOpacity" | "transform" | "fontColor";
export type TransformHandler<T> = (value: T) => DOMKeyframesDefinition;
type OverwriteMap = {
transform: React.CSSProperties["transform"];
scale: React.CSSProperties["scale"];
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;
/**
* Scale the current staging sequence.
* @param {number} scale - The scale of the transform.
* @returns {this} The current Transform instance for method chaining.
*/
scale(scale: TransformDefinitions.Types["scale"]): 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 {};