type Dict = Record; interface ComputedParams { context: BindableContext; event: EventType; prop: PropFn; refs: BindableRefs; scope: Scope; computed: ComputedFn; } interface ContextParams { prop: PropFn; bindable: BindableFn; scope: Scope; getContext: () => BindableContext; getComputed: () => ComputedFn; getRefs: () => BindableRefs; getEvent: () => EventType; flush: (fn: VoidFunction) => void; } export interface PropFn { (key: K): T["props"][K]; } export interface ComputedFn { (key: K): T["computed"][K]; } type AnyFunction = () => string | number | boolean | null | undefined; type TrackFn = (deps: AnyFunction[], fn: VoidFunction) => void; export interface BindableParams { defaultValue?: T | undefined; value?: T | undefined; hash?: ((a: T) => string) | undefined; isEqual?: ((a: T, b: T | undefined) => boolean) | undefined; onChange?: ((value: T, prev: T | undefined) => void) | undefined; debug?: string | undefined; sync?: boolean | undefined; } export type ValueOrFn = T | ((prev: T) => T); export interface Bindable { initial: T | undefined; ref: any; get: () => T; set(value: ValueOrFn): void; invoke(nextValue: T, prevValue: T): void; hash(value: T): string; } export interface BindableRefs { set(key: K, value: T["refs"][K]): void; get(key: K): T["refs"][K]; } export interface BindableContext { set(key: K, value: ValueOrFn): void; get(key: K): T["context"][K]; initial(key: K): T["context"][K]; hash(key: K): string; } interface BindableRef { get: () => T; set: (next: T) => void; } export interface BindableFn { (params: () => BindableParams): Bindable; cleanup: (fn: VoidFunction) => void; ref: (defaultValue: T) => BindableRef; } export interface Scope { id?: string | undefined; ids?: Record | undefined; getRootNode: () => ShadowRoot | Document | Element; getById: (id: string) => T | null; getActiveElement: () => HTMLElement | null; isActiveElement: (elem: HTMLElement | null) => boolean; getDoc: () => typeof document; getWin: () => typeof window; } type EventType = T & { previousEvent?: (T & { [key: string]: any; }) | undefined; src?: string | undefined; replaces?: string | undefined; [key: string]: any; }; export type EventObject = EventType<{ type: string; }>; export interface Params { prop: PropFn; action: (action: T["action"][]) => void; context: BindableContext; refs: BindableRefs; track: TrackFn; flush: (fn: VoidFunction) => void; event: EventType & { current: () => EventType; previous: () => EventType; }; send: (event: EventType) => void; computed: ComputedFn; scope: Scope; state: Bindable & { matches: (...values: T["state"][]) => boolean; hasTag: (tag: T["tag"]) => boolean; }; choose: ChooseFn; guard: (key: T["guard"] | GuardFn) => boolean | undefined; } export type GuardFn = (params: Params) => boolean; type TopLevelState = S extends `${infer Top}.${string}` ? Top : S; type ChildStateKey = S extends `${Parent}.${infer Rest}` ? Rest extends `${infer Child}.${string}` ? Child : Rest : never; type ParentPath = S extends `${infer Parent}.${string}` ? Parent : never; type AncestorPaths = S | (ParentPath extends never ? never : AncestorPaths>); type StateIdTarget = `#${string}`; type SiblingStateTarget = TopLevelState | ChildStateKey, Source>>; type ChildStateTarget = `.${ChildStateKey}`; export interface Transition { target?: T["state"] | StateIdTarget | (Source extends string ? SiblingStateTarget : never) | (Source extends string ? ChildStateTarget : never) | undefined; actions?: T["action"][] | undefined; guard?: T["guard"] | GuardFn | undefined; reenter?: boolean | undefined; } export type TransitionSet = Transition | Transition[] | undefined; export type TransitionMap = Record>; export type TransitionMatch = { transitions: TransitionSet; source: string | undefined; }; type MaybeArray = T | T[]; export type ChooseFn = (transitions: MaybeArray, "target">> | null | undefined) => Transition | undefined; interface PropsParams { props: Partial; scope: Scope; } interface RefsParams { prop: PropFn; context: BindableContext; } export type ActionsOrFn = T["action"][] | ((params: Params) => T["action"][] | undefined); export type EffectsOrFn = T["effect"][] | ((params: Params) => T["effect"][] | undefined); export interface MachineState { id?: string | undefined; tags?: T["tag"][] | undefined; entry?: ActionsOrFn | undefined; exit?: ActionsOrFn | undefined; effects?: EffectsOrFn | undefined; initial?: ChildStateKey | undefined; states?: { [K in ChildStateKey]?: MachineState; } | undefined; on?: { [E in T["event"]["type"]]?: Transition | Array>; } | undefined; } export interface Machine { debug?: boolean | undefined; props?: ((params: PropsParams) => T["props"]) | undefined; context?: ((params: ContextParams) => { [K in keyof T["context"]]: Bindable; }) | undefined; computed?: { [K in keyof T["computed"]]: (params: ComputedParams) => T["computed"][K]; } | undefined; initialState: (params: { prop: PropFn; }) => T["state"]; entry?: ActionsOrFn | undefined; exit?: ActionsOrFn | undefined; effects?: EffectsOrFn | undefined; refs?: ((params: RefsParams) => T["refs"]) | undefined; watch?: ((params: Params) => void) | undefined; on?: { [E in T["event"]["type"]]?: Transition | Array>; } | undefined; states: { [K in TopLevelState]: MachineState; }; implementations?: { guards?: { [K in T["guard"]]: (params: Params) => boolean; } | undefined; actions?: { [K in T["action"]]: (params: Params) => void; } | undefined; effects?: { [K in T["effect"]]: (params: Params) => void | VoidFunction; } | undefined; } | undefined; } interface MachineBaseProps { id?: string | undefined; ids?: Record | undefined; getRootNode?: (() => ShadowRoot | Document | Node) | undefined; [key: string]: any; } export interface MachineSchema { props?: MachineBaseProps | undefined; context?: Record | undefined; refs?: Record | undefined; computed?: Record | undefined; state?: string | undefined; tag?: string | undefined; guard?: string | undefined; action?: string | undefined; effect?: string | undefined; event?: ({ type: string; } & Dict) | undefined; } type State = Bindable & { hasTag: (tag: T["tag"]) => boolean; matches: (...values: T["state"][]) => boolean; }; export type Service = { getStatus: () => MachineStatus; state: State & { matches: (...values: T["state"][]) => boolean; hasTag: (tag: T["tag"]) => boolean; }; context: BindableContext; send: (event: EventType) => void; prop: PropFn; scope: Scope; computed: ComputedFn; refs: BindableRefs; event: EventType & { current: () => EventType; previous: () => EventType; }; }; export declare enum MachineStatus { NotStarted = "Not Started", Started = "Started", Stopped = "Stopped" } export declare const INIT_STATE = "__init__"; export {};