export interface IRouterSlot extends HTMLElement { readonly route: IRoute | null; readonly isRoot: boolean; readonly fragments: IPathFragments | null; readonly params: Params | null; readonly match: IRouteMatch | null; routes: IRoute[]; add: (routes: IRoute[], navigate?: boolean) => void; clear: () => void; render: () => Promise; constructAbsolutePath: (path: PathFragment) => string; parent: IRouterSlot

| null | undefined; queryParentRouterSlot: () => IRouterSlot

| null; } export type IRoutingInfo = { slot: IRouterSlot; match: IRouteMatch; }; export type CustomResolver = (info: IRoutingInfo) => boolean | void | Promise | Promise; export type Guard = (info: IRoutingInfo) => boolean | Promise; export type Cancel = () => boolean; export type PageComponent = HTMLElement | undefined; export type ModuleResolver = Promise<{ default?: any; element?: any; }>; export type Class = { new (...args: any[]): T; }; export type Component = Class | ModuleResolver | PageComponent | (() => Class) | (() => PromiseLike) | (() => PageComponent) | (() => PromiseLike) | (() => ModuleResolver) | (() => PromiseLike); export type Setup = (component: PageComponent, info: IRoutingInfo) => void; export type RouterTree = ({ slot: IRouterSlot; } & { child?: RouterTree; }) | null | undefined; export type PathMatch = 'prefix' | 'suffix' | 'full' | 'fuzzy'; /** * The base route interface. * D = the data type of the data */ export interface IRouteBase { path: PathFragment; data?: D; guards?: Guard[]; pathMatch?: PathMatch; unique?: string | symbol; } /** * Route type used for redirection. */ export interface IRedirectRoute extends IRouteBase { redirectTo: string; awaitStability?: boolean; preserveQuery?: boolean; } /** * Route type used to resolve and stamp components. */ export interface IComponentRoute extends IRouteBase { component: Component | PromiseLike; setup?: Setup; } /** * Route type used to take control of how the route should resolve. */ export interface IResolverRoute extends IRouteBase { resolve: CustomResolver; } export type IRoute = IRedirectRoute | IComponentRoute | IResolverRoute; export type PathFragment = string; export type IPathFragments = { consumed: PathFragment; rest: PathFragment; }; export interface IRouteMatch { route: IRoute; params: Params; fragments: IPathFragments; match: RegExpMatchArray; } export type PushStateEvent = CustomEvent; export type ReplaceStateEvent = CustomEvent; export type ChangeStateEvent = CustomEvent; export type WillChangeStateEvent = CustomEvent<{ url?: string | null; eventName: GlobalRouterEvent; }>; export type NavigationStartEvent = CustomEvent>; export type NavigationSuccessEvent = CustomEvent>; export type NavigationCancelEvent = CustomEvent>; export type NavigationErrorEvent = CustomEvent>; export type NavigationEndEvent = CustomEvent>; export type Params = { [key: string]: string; }; export type Query = { [key: string]: string; }; export type EventListenerSubscription = () => void; /** * RouterSlot related events. */ export type RouterSlotEvent = 'changestate'; /** * History related events. */ export type GlobalRouterEvent = 'pushstate' | 'replacestate' | 'popstate' | 'changestate' | 'willchangestate' | 'navigationstart' | 'navigationcancel' | 'navigationerror' | 'navigationsuccess' | 'navigationend'; export interface ISlashOptions { start: boolean; end: boolean; } declare global { interface GlobalEventHandlersEventMap { pushstate: PushStateEvent; replacestate: ReplaceStateEvent; popstate: PopStateEvent; changestate: ChangeStateEvent; navigationstart: NavigationStartEvent; navigationend: NavigationEndEvent; navigationsuccess: NavigationSuccessEvent; navigationcancel: NavigationCancelEvent; navigationerror: NavigationErrorEvent; willchangestate: WillChangeStateEvent; } }