///
import type {
Element as VElement,
TagFunc as IsoTagFunc,
} from "mini-van-plate/van-plate";
import type {
ChildDom,
Primitive,
Props,
PropsWithKnownKeys,
PropValueOrDerived,
State,
} from "vanjs-core";
import type { LayoutFile } from "../plugin/types.d.ts";
type PrimitiveChild = Primitive | State;
type DOMElement =
| SVGElement
| HTMLElement
| Node
| HTMLElementTagNameMap[T];
export type VanElement =
| DOMElement
| VElement
| PrimitiveChild;
export type VanNode =
| VanElement
| VanElement[]
| (() => VanElement | VanElement[])
| null
| undefined;
type ComponentProps1 = Props & PropsWithKnownKeys;
type ComponentProps =
& Props
& PropsWithKnownKeys;
export type VanComponent<
K extends keyof HTMLElementTagNameMap = "div",
O extends (Record | undefined) = undefined,
> = {
(
props?: O extends object ? ComponentProps & Partial
: ComponentProps,
...children: ChildDom[]
): HTMLElementTagNameMap[K];
};
// router.mjs
export const Router:
& VanComponent<"main">
& JSX.Component<"main">;
export const FileSystemRouter:
& VanComponent<"main">
& JSX.Component<"main">;
// a.mjs
export const A:
& VanComponent<"a">
& JSX.Component<"a">;
// helpers.mjs
export const navigate: (
href: string,
options?: { replace?: boolean },
) => void;
export const reload: () => void;
export const redirect: (href?: string) => void | (() => void);
export const getValue: (v: unknown) => string;
export const isCurrentPage: (pageName: string) => boolean;
export const isCurrentLocation: (pageName: string) => boolean;
export const isLazyComponent: (component: unknown) => boolean;
export const executeLifecycle: (
route: RouteEntry | {
preload?: (params?: Record) => unknown;
load?: (params?: Record) => Promise;
} | null,
) => Promise;
export const useRouteData: () => T | undefined;
export const matchRoute: (path: string) => RouteEntry | null;
// extractParams.mjs
export const extractParams: (
pattern: string,
path: string,
) => Record | null;
// routes.mjs
export type RouteEntry = {
path: string;
component: () => Promise;
params?: Record;
preload?: (params?: Record) => unknown;
load?: (params?: Record) => Promise;
};
export type ImportFn = () => LazyComponent;
export const lazy: (importFn: ImportFn) => () => Promise;
export type RouteProps = {
path: string;
params?: Record;
component:
| (() => DOMElement)
| VanComponent
| ComponentFn
| (() => Promise);
preload?: (params?: Record) => unknown;
load?: (params?: Record) => Promise;
};
export type RouteConfig = {
routePath: string;
path: string;
layouts?: LayoutFile[];
};
export const routes: RouteEntry[];
export const Route: (route: RouteProps) => void;
// state.mjs
export type RouterState = {
pathname: string;
searchParams: string;
params: Record;
loading: boolean;
};
export const routerState: {
pathname: RouterState["pathname"];
searchParams: RouterState["searchParams"];
params?: RouterState["params"];
loading: RouterState["loading"];
};
export const setRouterState: (
href: string,
search?: string,
params?: Record,
) => void;
export const microStore: >(init: T) => T;
// routeCache.mjs
export const cacheRoute: (key: ImportFn, value: ComponentModule) => void;
export const getCachedRoute: (key: ImportFn) => ComponentModule | undefined;
export const fixRouteUrl: (url: string) => string;
// unwrap.mjs
export type UnwrapResult = { children: VanNode[] };
export const unwrap: (
source:
| VanNode
| VanNode[]
| VanComponent
| { children: VanNode[] }
| ComponentFn
| ReturnType
| ReturnType[]
| (() =>
| ReturnType
| ReturnType[]
| VanNode
| VanNode[]),
...children: VanNode[]
) => UnwrapResult;
export type JSXComponentFn = () => JSX.Element;
export type FragmentFn = () => ChildDom | ChildDom[];
export type ComponentFn = FragmentFn | VanComponent | JSXComponentFn;
export type ComponentModule = {
component: ComponentFn;
route?: Pick;
};
export type LazyComponent = Promise<{
default?: ComponentFn;
Page?: ComponentFn;
route?: Pick;
}>;
// dataCache.mjs
export type CacheEntry = {
data: T;
error: Error | null;
timestamp: number;
};
export const dataCache: {
get(pathname: string, key: string): CacheEntry | undefined;
set(pathname: string, key: string, entry: Partial>): void;
has(pathname: string, key?: string): boolean;
getRoute(pathname: string): Record | undefined;
del(pathname: string, key?: string): boolean;
clear(): void;
touch(pathname: string): void;
toJSON(): Record>;
hydrateFromJSON(json: Record>): void;
size(): number;
setMaxRoutes(n: number): void;
};