@swan-io/chicane
Advanced tools
Comparing version 1.0.4 to 1.1.0
@@ -1,2 +0,721 @@ | ||
import { ConcatPaths } from "./types"; | ||
export declare const createGroup: <GroupName extends string, BasePath extends string, Routes extends Record<string, string>>(name: GroupName, basePath: BasePath, routes: Readonly<Routes>) => { [K in keyof Routes as K extends string ? `${GroupName}${K}` : never]: ConcatPaths<BasePath, Routes[K], import("./types").PrefixWithSlash<BasePath>, import("./types").PrefixWithSlash<Routes[K]>>; }; | ||
export declare const createGroup: <GroupName extends string, BaseRoute extends string, Routes extends Record<string, string>>(name: GroupName, baseRoute: BaseRoute, routes: Readonly<Routes>) => { [K in keyof Routes as K extends string ? `${GroupName}${K}` : never]: `${((BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"] extends `/${infer _}` ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"] : `/${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"]}`) extends "/" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"] extends `/${infer _}` ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"] : `/${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"]}` : ((Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"] extends `/${infer _}` ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"] : `/${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"]}`) extends "/" ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"] extends `/${infer _}` ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"] : `/${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"]}` : `${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"] extends `/${infer _}` ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"] : `/${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["path"]}`}${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"] extends `/${infer _}` ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"] : `/${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["path"]}`}`}${((BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["search"] extends "" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] : `${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["search"]}${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] extends "" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] : `&${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"]}`}`) extends "" ? "" & ((BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["search"] extends "" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] : `${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["search"]}${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] extends "" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] : `&${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"]}`}`) : `?${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["search"] extends "" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] : `${(BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["search"]}${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] extends "" ? (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"] : `&${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["search"]}`}`}`}${((Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["hash"] extends "" ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["hash"] : (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["hash"]) extends "" ? "" & ((Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["hash"] extends "" ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["hash"] : (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["hash"]) : `#${(Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["hash"] extends "" ? (BaseRoute extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BaseRoute extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BaseRoute extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BaseRoute; | ||
search: ""; | ||
hash: ""; | ||
})["hash"] : (Routes[K] extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Routes[K] extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : Routes[K] extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: Routes[K]; | ||
search: ""; | ||
hash: ""; | ||
})["hash"]}`}`; }; |
@@ -1,12 +0,252 @@ | ||
import { ExtractRoutesParams, GetNestedRoutes, ParamsArg, PrependBasePath, Simplify } from "./types"; | ||
import { ExtractRoutesParams, GetAreaRoutes, ParamsArg, PrependBasePath, Simplify } from "./types"; | ||
export declare const createRouter: <Routes extends Record<string, string>, BasePath extends string = string>(routes: Readonly<Routes>, options?: { | ||
basePath?: BasePath; | ||
}) => { | ||
useRoute: <RouteName extends keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>> | Exclude<keyof Routes, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>(routeNames: readonly RouteName[]) => RouteName extends string ? { | ||
useRoute: <RouteName extends keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>> | Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>(routeNames: readonly RouteName[]) => RouteName extends string ? { | ||
key: string; | ||
name: RouteName; | ||
params: Simplify<(ExtractRoutesParams<GetNestedRoutes<PrependBasePath<Routes, BasePath>>> & ExtractRoutesParams<Omit<PrependBasePath<Routes, BasePath>, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>)[RouteName]>; | ||
params: Simplify<(ExtractRoutesParams<GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>> & ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>)[RouteName]>; | ||
} | undefined : never; | ||
push: <RouteName_1 extends Exclude<keyof Routes, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>(routeName: RouteName_1, ...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<Routes, BasePath>, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>[RouteName_1]>) => void; | ||
replace: <RouteName_2 extends Exclude<keyof Routes, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>(routeName: RouteName_2, ...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<Routes, BasePath>, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>[RouteName_2]>) => void; | ||
} & { [RouteName_3 in keyof Omit<PrependBasePath<Routes, BasePath>, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>]: (...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<Routes, BasePath>, keyof GetNestedRoutes<PrependBasePath<Routes, BasePath>>>>[RouteName_3]>) => string; }; | ||
push: <RouteName_1 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>(routeName: RouteName_1, ...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>[RouteName_1]>) => void; | ||
replace: <RouteName_2 extends Exclude<keyof Routes, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>(routeName: RouteName_2, ...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>[RouteName_2]>) => void; | ||
} & { [RouteName_3 in keyof Omit<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>]: (...args: ParamsArg<ExtractRoutesParams<Omit<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>, keyof GetAreaRoutes<PrependBasePath<BasePath, Routes, BasePath extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : BasePath extends `${infer Path_1}?${infer Search_1}` ? { | ||
path: Path_1; | ||
search: Search_1; | ||
hash: ""; | ||
} : BasePath extends `${infer Path_2}#${infer Hash_1}` ? { | ||
path: Path_2; | ||
search: ""; | ||
hash: Hash_1; | ||
} : { | ||
path: BasePath; | ||
search: ""; | ||
hash: ""; | ||
}>>>>[RouteName_3]>) => string; }; |
@@ -12,3 +12,1 @@ export declare const first: <T>(value: T[]) => T | undefined; | ||
export declare const isMultipleParam: (value: string) => boolean; | ||
export declare const prefixWithSlash: (value: string) => string; | ||
export declare const concatPaths: (pathA: string, pathB: string) => string; |
@@ -1,2 +0,2 @@ | ||
import{createBrowserHistory as n,createPath as t,parsePath as r}from"history";import*as e from"react";import{useSyncExternalStoreWithSelector as a}from"use-sync-external-store/shim/with-selector";import{useSyncExternalStore as o}from"use-sync-external-store/shim";import i from"@emotion/hash";var u=function(n){return n[0]},l=function(n){return n},c=function(n){return""!==n},s=function(n){return n.startsWith(":")},f=function(n,t){return n.length===t.length&&n.every(function(n,r){return n===t[r]})},h=function(n,t){return(null==n?void 0:n.key)===(null==t?void 0:t.key)},p=function(n){return"/"===n[0]?n:"/"+n},v=function(n,t){var r=p(n),e=p(t);return"/"===r?e:"/"===e?r:r+e},m=function(n,t,r){var e={};for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[n+a]=v(t,r[a]));return e};function y(){return y=Object.assign||function(n){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},y.apply(this,arguments)}function d(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=new Array(t);r<t;r++)e[r]=n[r];return e}function g(n,t){var r="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(r)return(r=r.call(n)).next.bind(r);if(Array.isArray(n)||(r=function(n,t){if(n){if("string"==typeof n)return d(n,t);var r=Object.prototype.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(n,t):void 0}}(n))||t&&n&&"number"==typeof n.length){r&&(n=r);var e=0;return function(){return e>=n.length?{done:!0}:{done:!1,value:n[e++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var b=function(n){for(var t,r={},e=g(new URLSearchParams(n));!(t=e()).done;){var a=t.value,o=a[0],i=a[1],u=r[o];r[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return r},k=function(n,t,r){var e=n+(""!==n?"&":"")+encodeURIComponent(t);return""!==r?e+"="+encodeURIComponent(r):e},w=function(n){var t=Object.keys(n);if(0===t.length)return"";var r="";t.sort();for(var e=0,a=t;e<a.length;e++){var o=a[e],i=n[o];if(null!=i)if("string"==typeof i)r=k(r,o,i);else for(var u,l=g(i);!(u=l()).done;)r=k(r,o,u.value)}return""===r?"":"?"+r},O=function(n,t){var r=n.search,e=n.hash,a=n.pathname.substring(1),o=""!==a?t?a.split("/").filter(c).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],u=""!==r?b(r):{},l=""!==e?decodeURIComponent(e.substring(1)):null,s="/"+o.map(encodeURIComponent).join("/"),f=w(u),h=null!=l?"#"+encodeURIComponent(l):"",p=s+f+h;return y({key:i(s)+"-"+i(f+h),path:o,search:u},null!==l&&{hash:l},{raw:{path:s,search:f,hash:h},toString:function(){return p}})},C=new Set,S=n(),I=O(S.location,!0),R=!1;I.toString()!==t(S.location)&&S.replace(I.toString()),S.listen(function(n){var t=O(n.location,!1);if(t.toString()!==I.toString()){R=!0;var r=t.raw.search!==I.raw.search,e=r?{}:I.search;if(r)for(var a in t.search)if(Object.prototype.hasOwnProperty.call(t.search,a)){var o=t.search[a];if(null==o)continue;var i=I.search[a];e[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&f(o,i)?i:o}I=y({key:t.key,path:t.raw.path!==I.raw.path?t.path:I.path,search:e},null!=t.hash&&{hash:t.hash},{raw:t.raw,toString:t.toString}),C.forEach(function(n){return n(I)})}});var j=function(n){return C.add(n),function(){C.delete(n)}},U=function(){return I},P=function(){return o(j,U)},A=function(n){var t=r(n),e=t.pathname,a=t.search,o=t.hash;S.push({pathname:void 0===e?"":e,search:void 0===a?"":a,hash:void 0===o?"":o})},E=function(n){var t=r(n),e=t.pathname,a=t.search,o=t.hash;S.replace({pathname:void 0===e?"":e,search:void 0===a?"":a,hash:void 0===o?"":o})},N=function(n){for(var t,r=n.split("/").filter(c),e=[],a=r.length>0?4*r.length:5,o=g(r);!(t=o()).done;){var i=t.value,u=s(i);a+=u?2:3,e.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:e}},x=function(n,t){if(t.endsWith("*")){var e=r(t.slice(0,-1)).pathname,a=N(void 0===e?"/":e);return{finite:!1,name:n,ranking:a.ranking-1,path:a.path,search:{},hash:void 0}}for(var o,i=r(t),u=i.pathname,l=i.search,c=void 0===l?"":l,f=i.hash,h=void 0===f?"":f,p=N(void 0===u?"/":u),v=p.ranking,m=p.path,y={},d=g(new URLSearchParams(c.substring(1)));!(o=d()).done;){var b=o.value[0];(k=b).startsWith(":")&&k.endsWith("[]")?y[b.substring(1,b.length-2)]="multiple":s(b)&&(y[b.substring(1,b.length)]="unique")}return{finite:!0,name:n,ranking:v,path:m,search:y,hash:s(h.substring(1))?h.substring(2):void 0};var k},T=function(n,t){var r=n.path,e=t.finite,a=t.path;if(!(e&&r.length!==a.length||!e&&r.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=r[i],l=a[i];if(null!=l)if("string"==typeof l){if(l!==u)return}else{if(null==u)return;o[l.name]=u}}if(!e)return o;for(var c in t.search)if(Object.prototype.hasOwnProperty.call(t.search,c)){var s=t.search[c],f=n.search[c];if(null==s||null==f)continue;if("multiple"===s){o[c]="string"==typeof f?[f]:f;continue}"string"==typeof f?o[c]=f:null!=f[0]&&(o[c]=f[0])}return null!=t.hash&&null!=n.hash&&(o[t.hash]=n.hash),o}},K=function(n,t){void 0===t&&(t={});var r="/"+n.path.map(function(n){return encodeURIComponent("string"==typeof n?n:String(t[n.name]))}).join("/"),e="",a="";if(null!=n.search){var o={};for(var i in t){var u=t[i];Object.prototype.hasOwnProperty.call(t,i)&&Object.prototype.hasOwnProperty.call(n.search,i)&&null!=u&&(o[i]=u)}e=w(o)}if(null!=n.hash){var l=t[n.hash];"string"==typeof l&&(a="#"+encodeURIComponent(l))}return{pathname:r,search:e,hash:a}},L=function(n,r){void 0===r&&(r={});var o=r.basePath,i=void 0===o?"":o,c={},s=[];for(var f in n)if(Object.prototype.hasOwnProperty.call(n,f)){var p=x(f,v(i,n[f]));c[f]=p,s.push(p)}s.sort(function(n,t){return t.ranking-n.ranking});for(var m={},d=0;d<s.length;d++){var b=s[d];null!=b&&b.finite&&function(){var n=b.name;m[n]=function(r){return t(K(c[n],r))}}()}return y({useRoute:function(n){var t=e.useMemo(function(){return s.filter(function(t){return n.includes(t.name)})},[JSON.stringify(n)]);return a(j,function(){return function(n,t){for(var r,e=g(t);!(r=e()).done;){var a=r.value,o=T(n,a);if(null!=o)return{key:n.key,name:a.name,params:o}}}(U(),t)},void 0,l,h)},push:function(n){return S.push(K(c[n],u([].slice.call(arguments,1))))},replace:function(n){return S.replace(K(c[n],u([].slice.call(arguments,1))))}},m)},W=function(n){var t=n.href,a=n.replace,i=void 0!==a&&a,u=n.target,l=e.useMemo(function(){return r(t).pathname},[t]),c=o(j,function(){return l===U().raw.path}),s=i||c,f=!u||"_self"===u;return{active:c,onClick:e.useCallback(function(n){n.defaultPrevented||!f||0!==n.button||n.metaKey||n.altKey||n.ctrlKey||n.shiftKey||(n.preventDefault(),s?E(t):A(t))},[s,f,t])}},M=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],q=e.forwardRef(function(n,t){var r=n.onClick,a=n.className,o=n.replace,i=n.style,u=n.target,l=n.to,c=n.activeClassName,s=n.activeStyle,f=function(n,t){if(null==n)return{};var r,e,a={},o=Object.keys(n);for(e=0;e<o.length;e++)t.indexOf(r=o[e])>=0||(a[r]=n[r]);return a}(n,M),h=W({href:l,replace:o,target:u}),p=h.active,v=h.onClick;return e.createElement("a",y({},f,{ref:t,href:l,onClick:function(n){null==r||r(n),v(n)},target:u,className:p&&null!=c?null==a?c:a+" "+c:a,style:p&&null!=s?null==i?s:y({},i,s):i}))});q.displayName="Link";var D={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0},J=function(n){var t=n.route,r=n.containerRef,a=null==t?void 0:t.key.split("-")[0];e.useEffect(function(){var n=r.current;if(n&&R)try{null!=n.getAttribute("tabIndex")||D[n.nodeName]||n.setAttribute("tabIndex","-1"),n.focus()}catch(n){}},[r,a])},X=function(n,t){e.useEffect(function(){if(n){var r=S.block(function(n){window.confirm(t)&&(r(),n.retry())});return r}},[n])};export{q as Link,m as createGroup,L as createRouter,b as decodeSearch,w as encodeSearch,U as getLocation,A as pushUnsafe,E as replaceUnsafe,j as subscribeToLocation,J as useFocusReset,W as useLinkProps,P as useLocation,X as useNavigationBlocker}; | ||
import{parsePath as n,createBrowserHistory as r,createPath as t}from"history";import*as e from"react";import{useSyncExternalStoreWithSelector as a}from"use-sync-external-store/shim/with-selector";import{useSyncExternalStore as o}from"use-sync-external-store/shim";import i from"@emotion/hash";var u=function(n,r){return""===n?n:r+n},c=function(n){return"/"===n[0]?n:"/"+n},s=function(r){var t=n(r),e=t.pathname,a=t.search,o=t.hash,i=void 0===o?"":o;return{path:void 0===e?"":e,search:(void 0===a?"":a).substring(1),hash:i.substring(1)}},l=function(n,r){var t=c(n.path),e=c(r.path),a="/"===t?e:"/"===e?t:t+e,o=""===n.search?r.search:n.search+u(r.search,"&"),i=""===r.hash?n.hash:r.hash;return a+u(o,"?")+u(i,"#")},h=function(n,r,t){var e=s(r),a={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(a[n+o]=l(e,s(t[o])));return a};function f(){return f=Object.assign||function(n){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(n[e]=t[e])}return n},f.apply(this,arguments)}function p(n,r){(null==r||r>n.length)&&(r=n.length);for(var t=0,e=new Array(r);t<r;t++)e[t]=n[t];return e}function v(n,r){var t="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(t)return(t=t.call(n)).next.bind(t);if(Array.isArray(n)||(t=function(n,r){if(n){if("string"==typeof n)return p(n,r);var t=Object.prototype.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?p(n,r):void 0}}(n))||r&&n&&"number"==typeof n.length){t&&(n=t);var e=0;return function(){return e>=n.length?{done:!0}:{done:!1,value:n[e++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var m=function(n){return n[0]},d=function(n){return n},g=function(n){return""!==n},y=function(n){return n.startsWith(":")},b=function(n,r){return n.length===r.length&&n.every(function(n,t){return n===r[t]})},k=function(n,r){return(null==n?void 0:n.key)===(null==r?void 0:r.key)},w=function(n){for(var r,t={},e=v(new URLSearchParams(n));!(r=e()).done;){var a=r.value,o=a[0],i=a[1],u=t[o];t[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return t},O=function(n,r,t){var e=n+(""!==n?"&":"")+encodeURIComponent(r);return""!==t?e+"="+encodeURIComponent(t):e},C=function(n){var r=Object.keys(n);if(0===r.length)return"";var t="";r.sort();for(var e=0,a=r;e<a.length;e++){var o=a[e],i=n[o];if(null!=i)if("string"==typeof i)t=O(t,o,i);else for(var u,c=v(i);!(u=c()).done;)t=O(t,o,u.value)}return""===t?"":"?"+t},S=function(n,r){var t=n.search,e=n.hash,a=n.pathname.substring(1),o=""!==a?r?a.split("/").filter(g).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],u=""!==t?w(t):{},c=""!==e?decodeURIComponent(e.substring(1)):null,s="/"+o.map(encodeURIComponent).join("/"),l=C(u),h=null!=c?"#"+encodeURIComponent(c):"",p=s+l+h;return f({key:i(s)+"-"+i(l+h),path:o,search:u},null!==c&&{hash:c},{raw:{path:s,search:l,hash:h},toString:function(){return p}})},I=new Set,R=r(),j=S(R.location,!0),A=!1;j.toString()!==t(R.location)&&R.replace(j.toString()),R.listen(function(n){var r=S(n.location,!1);if(r.toString()!==j.toString()){A=!0;var t=r.raw.search!==j.raw.search,e=t?{}:j.search;if(t)for(var a in r.search)if(Object.prototype.hasOwnProperty.call(r.search,a)){var o=r.search[a];if(null==o)continue;var i=j.search[a];e[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&b(o,i)?i:o}j=f({key:r.key,path:r.raw.path!==j.raw.path?r.path:j.path,search:e},null!=r.hash&&{hash:r.hash},{raw:r.raw,toString:r.toString}),I.forEach(function(n){return n(j)})}});var U=function(n){return I.add(n),function(){I.delete(n)}},P=function(){return j},E=function(){return o(U,P)},N=function(r){var t=n(r),e=t.pathname,a=t.search,o=t.hash;R.push({pathname:void 0===e?"":e,search:void 0===a?"":a,hash:void 0===o?"":o})},x=function(r){var t=n(r),e=t.pathname,a=t.search,o=t.hash;R.replace({pathname:void 0===e?"":e,search:void 0===a?"":a,hash:void 0===o?"":o})},T=function(n){for(var r,t=n.split("/").filter(g),e=[],a=t.length>0?4*t.length:5,o=v(t);!(r=o()).done;){var i=r.value,u=y(i);a+=u?2:3,e.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:e}},K=function(r,t){if(t.endsWith("/*")){var e=n(t.slice(0,-2)).pathname,a=T(void 0===e?"/":e);return{isArea:!0,name:r,ranking:a.ranking-1,path:a.path,search:{},hash:void 0}}for(var o,i=n(t),u=i.pathname,c=i.search,s=void 0===c?"":c,l=i.hash,h=void 0===l?"":l,f=T(void 0===u?"/":u),p=f.ranking,m=f.path,d={},g=v(new URLSearchParams(s.substring(1)));!(o=g()).done;){var b=o.value[0];(k=b).startsWith(":")&&k.endsWith("[]")?d[b.substring(1,b.length-2)]="multiple":y(b)&&(d[b.substring(1,b.length)]="unique")}return{isArea:!1,name:r,ranking:p,path:m,search:d,hash:y(h.substring(1))?h.substring(2):void 0};var k},L=function(n,r){var t=n.path,e=r.isArea,a=r.path;if(!(!e&&t.length!==a.length||e&&t.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=t[i],c=a[i];if(null!=c)if("string"==typeof c){if(c!==u)return}else{if(null==u)return;o[c.name]=u}}if(e)return o;for(var s in r.search)if(Object.prototype.hasOwnProperty.call(r.search,s)){var l=r.search[s],h=n.search[s];if(null==l||null==h)continue;if("multiple"===l){o[s]="string"==typeof h?[h]:h;continue}"string"==typeof h?o[s]=h:null!=h[0]&&(o[s]=h[0])}return null!=r.hash&&null!=n.hash&&(o[r.hash]=n.hash),o}},W=function(n,r){void 0===r&&(r={});var t="/"+n.path.map(function(n){return encodeURIComponent("string"==typeof n?n:String(r[n.name]))}).join("/"),e="",a="";if(null!=n.search){var o={};for(var i in r){var u=r[i];Object.prototype.hasOwnProperty.call(r,i)&&Object.prototype.hasOwnProperty.call(n.search,i)&&null!=u&&(o[i]=u)}e=C(o)}if(null!=n.hash){var c=r[n.hash];"string"==typeof c&&(a="#"+encodeURIComponent(c))}return{pathname:t,search:e,hash:a}},M=function(n,r){void 0===r&&(r={});var o=r.basePath,i=void 0===o?"":o,u={path:s(i).path,search:"",hash:""},c={},h=[];for(var p in n)if(Object.prototype.hasOwnProperty.call(n,p)){var g=K(p,""!==i?l(u,s(n[p])):n[p]);c[p]=g,h.push(g)}h.sort(function(n,r){return r.ranking-n.ranking});for(var y={},b=0;b<h.length;b++){var w=h[b];null==w||w.isArea||function(){var n=w.name;y[n]=function(r){return t(W(c[n],r))}}()}return f({useRoute:function(n){var r=e.useMemo(function(){return h.filter(function(r){return n.includes(r.name)})},[JSON.stringify(n)]);return a(U,function(){return function(n,r){for(var t,e=v(r);!(t=e()).done;){var a=t.value,o=L(n,a);if(null!=o)return{key:n.key,name:a.name,params:o}}}(P(),r)},void 0,d,k)},push:function(n){return R.push(W(c[n],m([].slice.call(arguments,1))))},replace:function(n){return R.replace(W(c[n],m([].slice.call(arguments,1))))}},y)},q=function(r){var t=r.href,a=r.replace,i=void 0!==a&&a,u=r.target,c=e.useMemo(function(){return n(t).pathname},[t]),s=o(U,function(){return c===P().raw.path}),l=i||s,h=!u||"_self"===u;return{active:s,onClick:e.useCallback(function(n){n.defaultPrevented||!h||0!==n.button||n.metaKey||n.altKey||n.ctrlKey||n.shiftKey||(n.preventDefault(),l?x(t):N(t))},[l,h,t])}},D=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],J=e.forwardRef(function(n,r){var t=n.onClick,a=n.className,o=n.replace,i=n.style,u=n.target,c=n.to,s=n.activeClassName,l=n.activeStyle,h=function(n,r){if(null==n)return{};var t,e,a={},o=Object.keys(n);for(e=0;e<o.length;e++)r.indexOf(t=o[e])>=0||(a[t]=n[t]);return a}(n,D),p=q({href:c,replace:o,target:u}),v=p.active,m=p.onClick;return e.createElement("a",f({},h,{ref:r,href:c,onClick:function(n){null==t||t(n),m(n)},target:u,className:v&&null!=s?null==a?s:a+" "+s:a,style:v&&null!=l?null==i?l:f({},i,l):i}))});J.displayName="Link";var X={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0},$=function(n){var r=n.route,t=n.containerRef,a=null==r?void 0:r.key.split("-")[0];e.useEffect(function(){var n=t.current;if(n&&A)try{null!=n.getAttribute("tabIndex")||X[n.nodeName]||n.setAttribute("tabIndex","-1"),n.focus()}catch(n){}},[t,a])},_=function(n,r){e.useEffect(function(){if(n){var t=R.block(function(n){window.confirm(r)&&(t(),n.retry())});return t}},[n])};export{J as Link,h as createGroup,M as createRouter,w as decodeSearch,C as encodeSearch,P as getLocation,N as pushUnsafe,x as replaceUnsafe,U as subscribeToLocation,$ as useFocusReset,q as useLinkProps,E as useLocation,_ as useNavigationBlocker}; | ||
//# sourceMappingURL=index.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("history"),t=require("react"),r=require("use-sync-external-store/shim/with-selector"),n=require("use-sync-external-store/shim"),a=require("@emotion/hash");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var u=/*#__PURE__*/i(t),c=/*#__PURE__*/o(a),s=function(e){return e[0]},l=function(e){return e},f=function(e){return""!==e},h=function(e){return e.startsWith(":")},p=function(e,t){return e.length===t.length&&e.every(function(e,r){return e===t[r]})},v=function(e,t){return(null==e?void 0:e.key)===(null==t?void 0:t.key)},d=function(e){return"/"===e[0]?e:"/"+e},y=function(e,t){var r=d(e),n=d(t);return"/"===r?n:"/"===n?r:r+n};function g(){return g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function b(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return m(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?m(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var k=function(e){for(var t,r={},n=b(new URLSearchParams(e));!(t=n()).done;){var a=t.value,o=a[0],i=a[1],u=r[o];r[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return r},S=function(e,t,r){var n=e+(""!==e?"&":"")+encodeURIComponent(t);return""!==r?n+"="+encodeURIComponent(r):n},w=function(e){var t=Object.keys(e);if(0===t.length)return"";var r="";t.sort();for(var n=0,a=t;n<a.length;n++){var o=a[n],i=e[o];if(null!=i)if("string"==typeof i)r=S(r,o,i);else for(var u,c=b(i);!(u=c()).done;)r=S(r,o,u.value)}return""===r?"":"?"+r},O=function(e,t){var r=e.search,n=e.hash,a=e.pathname.substring(1),o=""!==a?t?a.split("/").filter(f).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],i=""!==r?k(r):{},u=""!==n?decodeURIComponent(n.substring(1)):null,s="/"+o.map(encodeURIComponent).join("/"),l=w(i),h=null!=u?"#"+encodeURIComponent(u):"",p=s+l+h;return g({key:c.default(s)+"-"+c.default(l+h),path:o,search:i},null!==u&&{hash:u},{raw:{path:s,search:l,hash:h},toString:function(){return p}})},x=new Set,P=e.createBrowserHistory(),j=O(P.location,!0),C=!1;j.toString()!==e.createPath(P.location)&&P.replace(j.toString()),P.listen(function(e){var t=O(e.location,!1);if(t.toString()!==j.toString()){C=!0;var r=t.raw.search!==j.raw.search,n=r?{}:j.search;if(r)for(var a in t.search)if(Object.prototype.hasOwnProperty.call(t.search,a)){var o=t.search[a];if(null==o)continue;var i=j.search[a];n[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&p(o,i)?i:o}j=g({key:t.key,path:t.raw.path!==j.raw.path?t.path:j.path,search:n},null!=t.hash&&{hash:t.hash},{raw:t.raw,toString:t.toString}),x.forEach(function(e){return e(j)})}});var R=function(e){return x.add(e),function(){x.delete(e)}},I=function(){return j},U=function(t){var r=e.parsePath(t),n=r.pathname,a=r.search,o=r.hash;P.push({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},E=function(t){var r=e.parsePath(t),n=r.pathname,a=r.search,o=r.hash;P.replace({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},A=function(e){for(var t,r=e.split("/").filter(f),n=[],a=r.length>0?4*r.length:5,o=b(r);!(t=o()).done;){var i=t.value,u=h(i);a+=u?2:3,n.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:n}},N=function(t,r){if(r.endsWith("*")){var n=e.parsePath(r.slice(0,-1)).pathname,a=A(void 0===n?"/":n);return{finite:!1,name:t,ranking:a.ranking-1,path:a.path,search:{},hash:void 0}}for(var o,i=e.parsePath(r),u=i.pathname,c=i.search,s=void 0===c?"":c,l=i.hash,f=void 0===l?"":l,p=A(void 0===u?"/":u),v=p.ranking,d=p.path,y={},g=b(new URLSearchParams(s.substring(1)));!(o=g()).done;){var m=o.value[0];(k=m).startsWith(":")&&k.endsWith("[]")?y[m.substring(1,m.length-2)]="multiple":h(m)&&(y[m.substring(1,m.length)]="unique")}return{finite:!0,name:t,ranking:v,path:d,search:y,hash:h(f.substring(1))?f.substring(2):void 0};var k},L=function(e,t){var r=e.path,n=t.finite,a=t.path;if(!(n&&r.length!==a.length||!n&&r.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=r[i],c=a[i];if(null!=c)if("string"==typeof c){if(c!==u)return}else{if(null==u)return;o[c.name]=u}}if(!n)return o;for(var s in t.search)if(Object.prototype.hasOwnProperty.call(t.search,s)){var l=t.search[s],f=e.search[s];if(null==l||null==f)continue;if("multiple"===l){o[s]="string"==typeof f?[f]:f;continue}"string"==typeof f?o[s]=f:null!=f[0]&&(o[s]=f[0])}return null!=t.hash&&null!=e.hash&&(o[t.hash]=e.hash),o}},q=function(e,t){void 0===t&&(t={});var r="/"+e.path.map(function(e){return encodeURIComponent("string"==typeof e?e:String(t[e.name]))}).join("/"),n="",a="";if(null!=e.search){var o={};for(var i in t){var u=t[i];Object.prototype.hasOwnProperty.call(t,i)&&Object.prototype.hasOwnProperty.call(e.search,i)&&null!=u&&(o[i]=u)}n=w(o)}if(null!=e.hash){var c=t[e.hash];"string"==typeof c&&(a="#"+encodeURIComponent(c))}return{pathname:r,search:n,hash:a}},T=function(t){var r=t.href,a=t.replace,o=void 0!==a&&a,i=t.target,c=u.useMemo(function(){return e.parsePath(r).pathname},[r]),s=n.useSyncExternalStore(R,function(){return c===I().raw.path}),l=o||s,f=!i||"_self"===i;return{active:s,onClick:u.useCallback(function(e){e.defaultPrevented||!f||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),l?E(r):U(r))},[l,f,r])}},W=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],K=u.forwardRef(function(e,t){var r=e.onClick,n=e.className,a=e.replace,o=e.style,i=e.target,c=e.to,s=e.activeClassName,l=e.activeStyle,f=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(a[r]=e[r]);return a}(e,W),h=T({href:c,replace:a,target:i}),p=h.active,v=h.onClick;return u.createElement("a",g({},f,{ref:t,href:c,onClick:function(e){null==r||r(e),v(e)},target:i,className:p&&null!=s?null==n?s:n+" "+s:n,style:p&&null!=l?null==o?l:g({},o,l):o}))});K.displayName="Link";var M={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0};exports.Link=K,exports.createGroup=function(e,t,r){var n={};for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(n[e+a]=y(t,r[a]));return n},exports.createRouter=function(t,n){void 0===n&&(n={});var a=n.basePath,o=void 0===a?"":a,i={},c=[];for(var f in t)if(Object.prototype.hasOwnProperty.call(t,f)){var h=N(f,y(o,t[f]));i[f]=h,c.push(h)}c.sort(function(e,t){return t.ranking-e.ranking});for(var p={},d=0;d<c.length;d++){var m=c[d];null!=m&&m.finite&&function(){var t=m.name;p[t]=function(r){return e.createPath(q(i[t],r))}}()}return g({useRoute:function(e){var t=u.useMemo(function(){return c.filter(function(t){return e.includes(t.name)})},[JSON.stringify(e)]);return r.useSyncExternalStoreWithSelector(R,function(){return function(e,t){for(var r,n=b(t);!(r=n()).done;){var a=r.value,o=L(e,a);if(null!=o)return{key:e.key,name:a.name,params:o}}}(I(),t)},void 0,l,v)},push:function(e){return P.push(q(i[e],s([].slice.call(arguments,1))))},replace:function(e){return P.replace(q(i[e],s([].slice.call(arguments,1))))}},p)},exports.decodeSearch=k,exports.encodeSearch=w,exports.getLocation=I,exports.pushUnsafe=U,exports.replaceUnsafe=E,exports.subscribeToLocation=R,exports.useFocusReset=function(e){var t=e.route,r=e.containerRef,n=null==t?void 0:t.key.split("-")[0];u.useEffect(function(){var e=r.current;if(e&&C)try{null!=e.getAttribute("tabIndex")||M[e.nodeName]||e.setAttribute("tabIndex","-1"),e.focus()}catch(e){}},[r,n])},exports.useLinkProps=T,exports.useLocation=function(){return n.useSyncExternalStore(R,I)},exports.useNavigationBlocker=function(e,t){u.useEffect(function(){if(e){var r=P.block(function(e){window.confirm(t)&&(r(),e.retry())});return r}},[e])}; | ||
var e=require("history"),r=require("react"),t=require("use-sync-external-store/shim/with-selector"),n=require("use-sync-external-store/shim"),a=require("@emotion/hash");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function i(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var u=/*#__PURE__*/i(r),c=/*#__PURE__*/o(a),s=function(e,r){return""===e?e:r+e},l=function(e){return"/"===e[0]?e:"/"+e},h=function(r){var t=e.parsePath(r),n=t.pathname,a=t.search,o=t.hash,i=void 0===o?"":o;return{path:void 0===n?"":n,search:(void 0===a?"":a).substring(1),hash:i.substring(1)}},f=function(e,r){var t=l(e.path),n=l(r.path),a="/"===t?n:"/"===n?t:t+n,o=""===e.search?r.search:e.search+s(r.search,"&"),i=""===r.hash?e.hash:r.hash;return a+s(o,"?")+s(i,"#")};function p(){return p=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},p.apply(this,arguments)}function v(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function d(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return v(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?v(e,r):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var y=function(e){return e[0]},g=function(e){return e},m=function(e){return""!==e},b=function(e){return e.startsWith(":")},k=function(e,r){return e.length===r.length&&e.every(function(e,t){return e===r[t]})},S=function(e,r){return(null==e?void 0:e.key)===(null==r?void 0:r.key)},w=function(e){for(var r,t={},n=d(new URLSearchParams(e));!(r=n()).done;){var a=r.value,o=a[0],i=a[1],u=t[o];t[o]=null!=u?"string"==typeof u?[u,i]:u.concat(i):i}return t},O=function(e,r,t){var n=e+(""!==e?"&":"")+encodeURIComponent(r);return""!==t?n+"="+encodeURIComponent(t):n},P=function(e){var r=Object.keys(e);if(0===r.length)return"";var t="";r.sort();for(var n=0,a=r;n<a.length;n++){var o=a[n],i=e[o];if(null!=i)if("string"==typeof i)t=O(t,o,i);else for(var u,c=d(i);!(u=c()).done;)t=O(t,o,u.value)}return""===t?"":"?"+t},x=function(e,r){var t=e.search,n=e.hash,a=e.pathname.substring(1),o=""!==a?r?a.split("/").filter(m).map(decodeURIComponent):a.split("/").map(decodeURIComponent):[],i=""!==t?w(t):{},u=""!==n?decodeURIComponent(n.substring(1)):null,s="/"+o.map(encodeURIComponent).join("/"),l=P(i),h=null!=u?"#"+encodeURIComponent(u):"",f=s+l+h;return p({key:c.default(s)+"-"+c.default(l+h),path:o,search:i},null!==u&&{hash:u},{raw:{path:s,search:l,hash:h},toString:function(){return f}})},j=new Set,C=e.createBrowserHistory(),R=x(C.location,!0),I=!1;R.toString()!==e.createPath(C.location)&&C.replace(R.toString()),C.listen(function(e){var r=x(e.location,!1);if(r.toString()!==R.toString()){I=!0;var t=r.raw.search!==R.raw.search,n=t?{}:R.search;if(t)for(var a in r.search)if(Object.prototype.hasOwnProperty.call(r.search,a)){var o=r.search[a];if(null==o)continue;var i=R.search[a];n[a]=null!=i&&"string"!=typeof i&&"string"!=typeof o&&k(o,i)?i:o}R=p({key:r.key,path:r.raw.path!==R.raw.path?r.path:R.path,search:n},null!=r.hash&&{hash:r.hash},{raw:r.raw,toString:r.toString}),j.forEach(function(e){return e(R)})}});var U=function(e){return j.add(e),function(){j.delete(e)}},A=function(){return R},E=function(r){var t=e.parsePath(r),n=t.pathname,a=t.search,o=t.hash;C.push({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},N=function(r){var t=e.parsePath(r),n=t.pathname,a=t.search,o=t.hash;C.replace({pathname:void 0===n?"":n,search:void 0===a?"":a,hash:void 0===o?"":o})},L=function(e){for(var r,t=e.split("/").filter(m),n=[],a=t.length>0?4*t.length:5,o=d(t);!(r=o()).done;){var i=r.value,u=b(i);a+=u?2:3,n.push(u?{name:i.substring(1)}:encodeURIComponent(i))}return{ranking:a,path:n}},q=function(r,t){if(t.endsWith("/*")){var n=e.parsePath(t.slice(0,-2)).pathname,a=L(void 0===n?"/":n);return{isArea:!0,name:r,ranking:a.ranking-1,path:a.path,search:{},hash:void 0}}for(var o,i=e.parsePath(t),u=i.pathname,c=i.search,s=void 0===c?"":c,l=i.hash,h=void 0===l?"":l,f=L(void 0===u?"/":u),p=f.ranking,v=f.path,y={},g=d(new URLSearchParams(s.substring(1)));!(o=g()).done;){var m=o.value[0];(k=m).startsWith(":")&&k.endsWith("[]")?y[m.substring(1,m.length-2)]="multiple":b(m)&&(y[m.substring(1,m.length)]="unique")}return{isArea:!1,name:r,ranking:p,path:v,search:y,hash:b(h.substring(1))?h.substring(2):void 0};var k},T=function(e,r){var t=e.path,n=r.isArea,a=r.path;if(!(!n&&t.length!==a.length||n&&t.length<a.length)){for(var o={},i=0;i<a.length;i++){var u=t[i],c=a[i];if(null!=c)if("string"==typeof c){if(c!==u)return}else{if(null==u)return;o[c.name]=u}}if(n)return o;for(var s in r.search)if(Object.prototype.hasOwnProperty.call(r.search,s)){var l=r.search[s],h=e.search[s];if(null==l||null==h)continue;if("multiple"===l){o[s]="string"==typeof h?[h]:h;continue}"string"==typeof h?o[s]=h:null!=h[0]&&(o[s]=h[0])}return null!=r.hash&&null!=e.hash&&(o[r.hash]=e.hash),o}},W=function(e,r){void 0===r&&(r={});var t="/"+e.path.map(function(e){return encodeURIComponent("string"==typeof e?e:String(r[e.name]))}).join("/"),n="",a="";if(null!=e.search){var o={};for(var i in r){var u=r[i];Object.prototype.hasOwnProperty.call(r,i)&&Object.prototype.hasOwnProperty.call(e.search,i)&&null!=u&&(o[i]=u)}n=P(o)}if(null!=e.hash){var c=r[e.hash];"string"==typeof c&&(a="#"+encodeURIComponent(c))}return{pathname:t,search:n,hash:a}},K=function(r){var t=r.href,a=r.replace,o=void 0!==a&&a,i=r.target,c=u.useMemo(function(){return e.parsePath(t).pathname},[t]),s=n.useSyncExternalStore(U,function(){return c===A().raw.path}),l=o||s,h=!i||"_self"===i;return{active:s,onClick:u.useCallback(function(e){e.defaultPrevented||!h||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),l?N(t):E(t))},[l,h,t])}},M=["onClick","className","replace","style","target","to","activeClassName","activeStyle"],_=u.forwardRef(function(e,r){var t=e.onClick,n=e.className,a=e.replace,o=e.style,i=e.target,c=e.to,s=e.activeClassName,l=e.activeStyle,h=function(e,r){if(null==e)return{};var t,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r.indexOf(t=o[n])>=0||(a[t]=e[t]);return a}(e,M),f=K({href:c,replace:a,target:i}),v=f.active,d=f.onClick;return u.createElement("a",p({},h,{ref:r,href:c,onClick:function(e){null==t||t(e),d(e)},target:i,className:v&&null!=s?null==n?s:n+" "+s:n,style:v&&null!=l?null==o?l:p({},o,l):o}))});_.displayName="Link";var B={A:!0,INPUT:!0,SELECT:!0,TEXTAREA:!0};exports.Link=_,exports.createGroup=function(e,r,t){var n=h(r),a={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(a[e+o]=f(n,h(t[o])));return a},exports.createRouter=function(r,n){void 0===n&&(n={});var a=n.basePath,o=void 0===a?"":a,i={path:h(o).path,search:"",hash:""},c={},s=[];for(var l in r)if(Object.prototype.hasOwnProperty.call(r,l)){var v=q(l,""!==o?f(i,h(r[l])):r[l]);c[l]=v,s.push(v)}s.sort(function(e,r){return r.ranking-e.ranking});for(var m={},b=0;b<s.length;b++){var k=s[b];null==k||k.isArea||function(){var r=k.name;m[r]=function(t){return e.createPath(W(c[r],t))}}()}return p({useRoute:function(e){var r=u.useMemo(function(){return s.filter(function(r){return e.includes(r.name)})},[JSON.stringify(e)]);return t.useSyncExternalStoreWithSelector(U,function(){return function(e,r){for(var t,n=d(r);!(t=n()).done;){var a=t.value,o=T(e,a);if(null!=o)return{key:e.key,name:a.name,params:o}}}(A(),r)},void 0,g,S)},push:function(e){return C.push(W(c[e],y([].slice.call(arguments,1))))},replace:function(e){return C.replace(W(c[e],y([].slice.call(arguments,1))))}},m)},exports.decodeSearch=w,exports.encodeSearch=P,exports.getLocation=A,exports.pushUnsafe=E,exports.replaceUnsafe=N,exports.subscribeToLocation=U,exports.useFocusReset=function(e){var r=e.route,t=e.containerRef,n=null==r?void 0:r.key.split("-")[0];u.useEffect(function(){var e=t.current;if(e&&I)try{null!=e.getAttribute("tabIndex")||B[e.nodeName]||e.setAttribute("tabIndex","-1"),e.focus()}catch(e){}},[t,n])},exports.useLinkProps=K,exports.useLocation=function(){return n.useSyncExternalStore(U,A)},exports.useNavigationBlocker=function(e,r){u.useEffect(function(){if(e){var t=C.block(function(e){window.confirm(r)&&(t(),e.retry())});return t}},[e])}; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,5 @@ export declare type Search = Record<string, string | string[]>; | ||
export declare type Matcher = { | ||
isArea: boolean; | ||
name: string; | ||
ranking: number; | ||
path: (string | { | ||
@@ -12,5 +14,13 @@ name: string; | ||
hash: string | undefined; | ||
finite: boolean; | ||
ranking: number; | ||
}; | ||
export declare type RouteObject = Readonly<{ | ||
path: string; | ||
search: string; | ||
hash: string; | ||
}>; | ||
export declare type RawLocation = Readonly<{ | ||
path: string; | ||
search: string; | ||
hash: string; | ||
}>; | ||
export declare type Location = Readonly<{ | ||
@@ -21,7 +31,3 @@ key: string; | ||
hash?: string; | ||
raw: Readonly<{ | ||
path: string; | ||
search: string; | ||
hash: string; | ||
}>; | ||
raw: RawLocation; | ||
toString(): string; | ||
@@ -34,18 +40,43 @@ }>; | ||
declare type ExtractSearchParams<Search extends string, Parts = SplitAndFilterEmpty<Search, "&">> = Parts extends [infer Head, ...infer Tail] ? Head extends `:${infer Name}[]` ? { | ||
[K in Name]?: string[]; | ||
[K in Name]?: string[] | undefined; | ||
} & ExtractSearchParams<Search, Tail> : Head extends `:${infer Name}` ? { | ||
[K in Name]?: string; | ||
[K in Name]?: string | undefined; | ||
} & ExtractSearchParams<Search, Tail> : ExtractSearchParams<Search, Tail> : {}; | ||
declare type ExtractHashParam<Value extends string> = Value extends `:${infer Name}` ? { | ||
[K in Name]?: string; | ||
declare type ExtractHashParams<Value extends string> = Value extends `:${infer Name}` ? { | ||
[K in Name]?: string | undefined; | ||
} : {}; | ||
declare type ExtractRouteParams<Route extends string> = Route extends `${infer Path}?${infer Search}#${infer Hash}` ? ExtractPathParams<Path> & ExtractSearchParams<Search> & ExtractHashParam<Hash> : Route extends `${infer Path}?${infer Search}` ? ExtractPathParams<Path> & ExtractSearchParams<Search> : Route extends `${infer Path}#${infer Hash}` ? ExtractPathParams<Path> & ExtractHashParam<Hash> : ExtractPathParams<Route>; | ||
export declare type PrefixWithSlash<Path extends string> = Path extends `/${infer _}` ? Path : `/${Path}`; | ||
export declare type ConcatPaths<PathA extends string, PathB extends string, PrefixedPathA extends string = PrefixWithSlash<PathA>, PrefixedPathB extends string = PrefixWithSlash<PathB>> = PrefixedPathA extends "/" ? PrefixedPathB : PrefixedPathB extends "/" ? PrefixedPathA : `${PrefixedPathA}${PrefixedPathB}`; | ||
export declare type PrependBasePath<Routes extends Record<string, string>, BasePath extends string> = { | ||
[K in keyof Routes]: ConcatPaths<BasePath, Routes[K]>; | ||
declare type ExtractRoute<Route extends string> = Route extends `${infer Path}?${infer Search}#${infer Hash}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: Hash; | ||
} : Route extends `${infer Path}?${infer Search}` ? { | ||
path: Path; | ||
search: Search; | ||
hash: ""; | ||
} : Route extends `${infer Path}#${infer Hash}` ? { | ||
path: Path; | ||
search: ""; | ||
hash: Hash; | ||
} : { | ||
path: Route; | ||
search: ""; | ||
hash: ""; | ||
}; | ||
export declare type GetNestedRoutes<Routes extends Record<string, string>> = { | ||
[K in keyof Routes as Routes[K] extends `${infer _}*` ? K : never]: Routes[K] extends `${infer Rest}*` ? Rest : never; | ||
declare type ExtractRouteParams<Route extends string, ExtractedRoute extends RouteObject = ExtractRoute<Route>> = ExtractPathParams<ExtractedRoute["path"]> & ExtractSearchParams<ExtractedRoute["search"]> & ExtractHashParams<ExtractedRoute["hash"]>; | ||
declare type AddPrefixOnNonEmpty<Value extends string, Prefix extends string> = Value extends "" ? Value : `${Prefix}${Value}`; | ||
declare type EnsureSlashPrefix<Value extends string> = Value extends `/${infer _}` ? Value : `/${Value}`; | ||
declare type ConcatPaths<PathA extends string, PathB extends string, FixedPathA extends string = EnsureSlashPrefix<PathA>, FixedPathB extends string = EnsureSlashPrefix<PathB>> = FixedPathA extends "/" ? FixedPathB : FixedPathB extends "/" ? FixedPathA : `${FixedPathA}${FixedPathB}`; | ||
declare type ConcatSearchs<SearchA extends string, SearchB extends string> = SearchA extends "" ? SearchB : `${SearchA}${AddPrefixOnNonEmpty<SearchB, "&">}`; | ||
declare type StringifyRouteObject<Route extends RouteObject> = `${Route["path"]}${AddPrefixOnNonEmpty<Route["search"], "?">}${AddPrefixOnNonEmpty<Route["hash"], "#">}`; | ||
export declare type ConcatRoutes<RouteA extends string, RouteB extends string, ExtractedRouteA extends RouteObject = ExtractRoute<RouteA>, ExtractedRouteB extends RouteObject = ExtractRoute<RouteB>> = StringifyRouteObject<{ | ||
path: ConcatPaths<ExtractedRouteA["path"], ExtractedRouteB["path"]>; | ||
search: ConcatSearchs<ExtractedRouteA["search"], ExtractedRouteB["search"]>; | ||
hash: ExtractedRouteB["hash"] extends "" ? ExtractedRouteA["hash"] : ExtractedRouteB["hash"]; | ||
}>; | ||
export declare type PrependBasePath<BasePath extends string, Routes extends Record<string, string>, ExtractedBase extends RouteObject = ExtractRoute<BasePath>> = { | ||
[K in keyof Routes]: ConcatRoutes<ExtractedBase["path"], Routes[K]>; | ||
}; | ||
export declare type GetAreaRoutes<Routes extends Record<string, string>> = { | ||
[K in keyof Routes as Routes[K] extends `${infer _}/*` ? K : never]: Routes[K] extends `${infer Rest}/*` ? Rest : never; | ||
}; | ||
export declare type ExtractRoutesParams<Routes extends Record<string, string>> = { | ||
@@ -52,0 +83,0 @@ [K in keyof Routes]: ExtractRouteParams<Routes[K]>; |
{ | ||
"name": "@swan-io/chicane", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -58,10 +58,10 @@ "description": "A simple and safe router for React and TypeScript", | ||
"devDependencies": { | ||
"@babel/core": "^7.17.9", | ||
"@babel/core": "^7.17.10", | ||
"@babel/plugin-transform-react-jsx": "^7.17.3", | ||
"@babel/preset-env": "^7.16.11", | ||
"@babel/preset-env": "^7.17.10", | ||
"@babel/preset-typescript": "^7.16.7", | ||
"@testing-library/jest-dom": "^5.16.4", | ||
"@testing-library/react": "^12.1.5", | ||
"@types/jest": "^27.4.1", | ||
"@types/react": "^17.0.44", | ||
"@types/jest": "^27.5.1", | ||
"@types/react": "^17.0.45", | ||
"@types/use-sync-external-store": "^0.0.3", | ||
@@ -75,4 +75,4 @@ "babel-jest": "^27.5.1", | ||
"react-dom": "^17.0.2", | ||
"typescript": "^4.6.3" | ||
"typescript": "^4.6.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
132153
21
1230
1