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; } interface PropFn { (key: K): T["props"][K]; } interface ComputedFn { (key: K): T["computed"][K]; } type AnyFunction = () => string | number | boolean | null | undefined; type TrackFn = (deps: AnyFunction[], fn: VoidFunction) => void; 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; } type ValueOrFn = T | ((prev: T) => T); interface Bindable { initial: T | undefined; ref: any; get: () => T; set(value: ValueOrFn): void; invoke(nextValue: T, prevValue: T): void; hash(value: T): string; } interface BindableRefs { set(key: K, value: T["refs"][K]): void; get(key: K): T["refs"][K]; } 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; } interface BindableFn { (params: () => BindableParams): Bindable; cleanup: (fn: VoidFunction) => void; ref: (defaultValue: T) => BindableRef; } 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; }; type EventObject = EventType<{ type: string; }>; 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; } 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}`; 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; } type TransitionSet = Transition | Transition[] | undefined; type TransitionMap = Record>; type TransitionMatch = { transitions: TransitionSet; source: string | undefined; }; type MaybeArray = T | T[]; type ChooseFn = (transitions: MaybeArray, "target">> | null | undefined) => Transition | undefined; interface PropsParams { props: Partial; scope: Scope; } interface RefsParams { prop: PropFn; context: BindableContext; } type ActionsOrFn = T["action"][] | ((params: Params) => T["action"][] | undefined); type EffectsOrFn = T["effect"][] | ((params: Params) => T["effect"][] | undefined); 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; } 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; } 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; }; 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; }; }; declare enum MachineStatus { NotStarted = "Not Started", Started = "Started", Stopped = "Stopped" } declare const INIT_STATE = "__init__"; export { type ActionsOrFn, type Bindable, type BindableContext, type BindableFn, type BindableParams, type BindableRefs, type ChooseFn, type ComputedFn, type EffectsOrFn, type EventObject, type GuardFn, INIT_STATE, type Machine, type MachineSchema, type MachineState, MachineStatus, type Params, type PropFn, type Scope, type Service, type Transition, type TransitionMap, type TransitionMatch, type TransitionSet, type ValueOrFn };