pose-core
Version:
Factory for Pose animation state machines
121 lines (120 loc) • 5.64 kB
TypeScript
export declare type Props = {
[key: string]: any;
};
export declare type NumberPropFactory = (props: Props) => number;
export declare type BooleanPropFactory = (props: Props) => boolean;
export declare type StaggerDirectionPropFactory = (props: Props) => 1 | -1;
export declare type TransitionFactory<A, TD> = (props: Props) => TD | A | false;
export declare type ApplyResolve = (props: Props) => string | number;
export declare type ApplyMap = {
[key: string]: ApplyResolve | string | number;
};
export declare type TransitionMap<A, TD> = {
[key: string]: TD | A | false | TransitionFactory<A, TD>;
};
export declare type TransitionMapFactory<A, TD> = (props: Props) => TransitionMap<A, TD>;
export declare type Pose<A, TD> = {
transition?: TransitionMap<A, TD> | TransitionMapFactory<A, TD>;
delay?: number | NumberPropFactory;
delayChildren?: number | NumberPropFactory;
staggerChildren?: number | NumberPropFactory;
staggerDirection?: 1 | -1 | StaggerDirectionPropFactory;
beforeChildren?: boolean | BooleanPropFactory;
afterChildren?: boolean | BooleanPropFactory;
preTransform?: () => any;
preTransition?: (props: Props) => any;
applyAtStart?: ApplyMap;
applyAtEnd?: ApplyMap;
[key: string]: any;
};
export declare type ValueMap<V> = Map<string, V>;
export declare type AncestorValue<V> = {
label?: string;
values: ValueMap<V>;
};
export declare type AncestorValueList<V> = Array<AncestorValue<V>>;
export declare type Transformer = (v: any) => any;
export declare type PassiveValueMap = {
[key: string]: [string, any, boolean | string | void];
};
export declare type OnChangeCallbacks = {
[key: string]: (v: any) => any;
};
export declare type ActiveActions<A> = Map<string, A>;
export declare type ActivePoses = Map<string, string[]>;
export declare type ChildPosers<V, A, C, P> = Set<Poser<V, A, C, P>>;
export declare type PoseMap<A, TD> = {
[key: string]: Pose<A, TD>;
};
export declare type PoserFactory<V, A, C, P> = (config: PoserConfig<V>) => Poser<V, A, C, P>;
export interface Poser<V, A, C, P> {
set: (next: string, props?: Props) => Promise<any>;
unset: (toUnset: string, props?: Props) => Promise<any>;
get: (key?: string) => any;
has: (key: string) => boolean;
setProps: (props: Props) => void;
destroy: () => void;
_addChild: (config: PoserConfig<V>, factory: PoserFactory<V, A, C, P>) => Poser<V, A, C, P>;
removeChild: (child: Poser<V, A, C, P>) => void;
clearChildren: () => void;
}
export declare type PoserState<V, A, C, P> = {
activeActions: ActiveActions<C>;
activePoses: ActivePoses;
children: ChildPosers<V, A, C, P>;
values: ValueMap<V>;
props: Props;
};
export declare type PoserConfig<V> = {
[key: string]: any;
label?: string;
props?: Props;
values?: {
[key: string]: V;
};
parentValues?: ValueMap<V>;
ancestorValues?: AncestorValueList<V>;
onChange?: OnChangeCallbacks;
passive?: PassiveValueMap;
initialPose?: string | string[];
};
export declare type ReadValue<V> = (value: V) => any;
export declare type ResolveTarget<V> = (value: V, target: any) => any;
export declare type CreateValueProps = any;
export declare type CreateValue<V> = (init: any, key: string, props: Props, createValueProps?: CreateValueProps) => V;
export declare type ConvertValue<V> = (value: any, key: string, props: Props) => V;
export declare type StartAction<V, A, C> = (value: V, action: A, complete: () => any) => C;
export declare type StopAction<C> = (controls: C) => any;
export declare type GetInstantTransition<V, A> = (value: V, props: Props) => A;
export declare type AddTransitionDelay<A> = (delay: number, transition: A) => A;
export declare type ExtendAPI<V, A, C, P> = (api: Poser<V, A, C, P>, state: PoserState<V, A, C, P>, config: PoserConfig<V>) => Poser<V, A, C, P>;
export declare type GetTransitionProps<V> = (value: V, target: number, props: Props) => Props;
export declare type SelectValueToRead<V> = (value: V) => any;
export declare type TransformPose<V, A, C, P, TD> = (pose: Pose<A, TD>, key: string, state: PoserState<V, A, C, P>) => Pose<A, TD>;
export declare type ReadValueFromSource = (key: string, props: Props) => any;
export declare type SetValue<V> = (v: V, value: any) => void;
export declare type SetValueNative = (key: string, value: any, props: Props) => void;
export declare type ConvertTransitionDefinition<V, A, TD> = (value: V, transitionDef: TD | A, props: Props) => A;
export declare type PoseFactoryConfig<V, A, C, P, TD> = {
getDefaultProps?: (config: PoserConfig<V>) => Props;
defaultTransitions?: Map<string, TransitionMap<A, TD>>;
bindOnChange: (values: ValueMap<V>, onChange: OnChangeCallbacks) => (key: string) => any;
readValue: ReadValue<V>;
readValueFromSource?: ReadValueFromSource;
setValue: SetValue<V>;
setValueNative: SetValueNative;
createValue: CreateValue<V>;
convertValue: ConvertValue<V>;
resolveTarget: ResolveTarget<V>;
getTransitionProps: GetTransitionProps<V>;
convertTransitionDefinition: ConvertTransitionDefinition<V, A, TD>;
startAction: StartAction<V, A, C>;
stopAction: StopAction<C>;
getInstantTransition: GetInstantTransition<V, A>;
addActionDelay: AddTransitionDelay<A>;
selectValueToRead: SelectValueToRead<V>;
extendAPI: ExtendAPI<V, A, C, P>;
transformPose?: TransformPose<V, A, C, P, TD>;
posePriority?: string[];
forceRender?: (props: Props) => any;
};