import { trimPathLeft, joinPaths } from "./path.js"; import { notFound } from "./not-found.js"; import { rootRouteId } from "./root.js"; class BaseRoute { constructor(options) { this.init = (opts) => { var _a, _b; this.originalIndex = opts.originalIndex; const options2 = this.options; const isRoot = !(options2 == null ? void 0 : options2.path) && !(options2 == null ? void 0 : options2.id); this.parentRoute = (_b = (_a = this.options).getParentRoute) == null ? void 0 : _b.call(_a); if (isRoot) { this._path = rootRouteId; } else if (!this.parentRoute) { throw new Error( `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.` ); } let path = isRoot ? rootRouteId : options2 == null ? void 0 : options2.path; if (path && path !== "/") { path = trimPathLeft(path); } const customId = (options2 == null ? void 0 : options2.id) || path; let id = isRoot ? rootRouteId : joinPaths([ this.parentRoute.id === rootRouteId ? "" : this.parentRoute.id, customId ]); if (path === rootRouteId) { path = "/"; } if (id !== rootRouteId) { id = joinPaths(["/", id]); } const fullPath = id === rootRouteId ? "/" : joinPaths([this.parentRoute.fullPath, path]); this._path = path; this._id = id; this._fullPath = fullPath; this._to = fullPath; this._ssr = (options2 == null ? void 0 : options2.ssr) ?? opts.defaultSsr ?? true; }; this.addChildren = (children) => { return this._addFileChildren(children); }; this._addFileChildren = (children) => { if (Array.isArray(children)) { this.children = children; } if (typeof children === "object" && children !== null) { this.children = Object.values(children); } return this; }; this._addFileTypes = () => { return this; }; this.updateLoader = (options2) => { Object.assign(this.options, options2); return this; }; this.update = (options2) => { Object.assign(this.options, options2); return this; }; this.lazy = (lazyFn) => { this.lazyFn = lazyFn; return this; }; this.options = options || {}; this.isRoot = !(options == null ? void 0 : options.getParentRoute); if ((options == null ? void 0 : options.id) && (options == null ? void 0 : options.path)) { throw new Error(`Route cannot have both an 'id' and a 'path' option.`); } } get to() { return this._to; } get id() { return this._id; } get path() { return this._path; } get fullPath() { return this._fullPath; } get ssr() { return this._ssr; } } class BaseRouteApi { constructor({ id }) { this.notFound = (opts) => { return notFound({ routeId: this.id, ...opts }); }; this.id = id; } } class BaseRootRoute extends BaseRoute { constructor(options) { super(options); } } export { BaseRootRoute, BaseRoute, BaseRouteApi }; //# sourceMappingURL=route.js.map