@tanstack/router-core 1.131.38 → 1.131.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { Store, batch } from "@tanstack/store";
2
2
  import { createMemoryHistory, createBrowserHistory, parseHref } from "@tanstack/history";
3
- import invariant from "tiny-invariant";
4
3
  import { createControlledPromise, deepEqual, replaceEqualDeep, last, findLast, functionalUpdate } from "./utils.js";
5
- import { trimPath, resolvePath, cleanPath, matchPathname, trimPathRight, interpolatePath, joinPaths, trimPathLeft, parsePathname, SEGMENT_TYPE_PARAM, SEGMENT_TYPE_OPTIONAL_PARAM, SEGMENT_TYPE_WILDCARD, SEGMENT_TYPE_PATHNAME } from "./path.js";
4
+ import { processRouteTree } from "./process-route-tree.js";
5
+ import { trimPath, resolvePath, cleanPath, matchPathname, trimPathRight, interpolatePath, joinPaths } from "./path.js";
6
6
  import { isNotFound } from "./not-found.js";
7
7
  import { setupScrollRestoration } from "./scroll-restoration.js";
8
8
  import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
@@ -1144,136 +1144,6 @@ function validateSearch(validateSearch2, input) {
1144
1144
  }
1145
1145
  return {};
1146
1146
  }
1147
- const REQUIRED_PARAM_BASE_SCORE = 0.5;
1148
- const OPTIONAL_PARAM_BASE_SCORE = 0.4;
1149
- const WILDCARD_PARAM_BASE_SCORE = 0.25;
1150
- const BOTH_PRESENCE_BASE_SCORE = 0.05;
1151
- const PREFIX_PRESENCE_BASE_SCORE = 0.02;
1152
- const SUFFIX_PRESENCE_BASE_SCORE = 0.01;
1153
- const PREFIX_LENGTH_SCORE_MULTIPLIER = 2e-4;
1154
- const SUFFIX_LENGTH_SCORE_MULTIPLIER = 1e-4;
1155
- function handleParam(segment, baseScore) {
1156
- if (segment.prefixSegment && segment.suffixSegment) {
1157
- return baseScore + BOTH_PRESENCE_BASE_SCORE + PREFIX_LENGTH_SCORE_MULTIPLIER * segment.prefixSegment.length + SUFFIX_LENGTH_SCORE_MULTIPLIER * segment.suffixSegment.length;
1158
- }
1159
- if (segment.prefixSegment) {
1160
- return baseScore + PREFIX_PRESENCE_BASE_SCORE + PREFIX_LENGTH_SCORE_MULTIPLIER * segment.prefixSegment.length;
1161
- }
1162
- if (segment.suffixSegment) {
1163
- return baseScore + SUFFIX_PRESENCE_BASE_SCORE + SUFFIX_LENGTH_SCORE_MULTIPLIER * segment.suffixSegment.length;
1164
- }
1165
- return baseScore;
1166
- }
1167
- function processRouteTree({
1168
- routeTree,
1169
- initRoute
1170
- }) {
1171
- const routesById = {};
1172
- const routesByPath = {};
1173
- const recurseRoutes = (childRoutes) => {
1174
- childRoutes.forEach((childRoute, i) => {
1175
- initRoute == null ? void 0 : initRoute(childRoute, i);
1176
- const existingRoute = routesById[childRoute.id];
1177
- invariant(
1178
- !existingRoute,
1179
- `Duplicate routes found with id: ${String(childRoute.id)}`
1180
- );
1181
- routesById[childRoute.id] = childRoute;
1182
- if (!childRoute.isRoot && childRoute.path) {
1183
- const trimmedFullPath = trimPathRight(childRoute.fullPath);
1184
- if (!routesByPath[trimmedFullPath] || childRoute.fullPath.endsWith("/")) {
1185
- routesByPath[trimmedFullPath] = childRoute;
1186
- }
1187
- }
1188
- const children = childRoute.children;
1189
- if (children == null ? void 0 : children.length) {
1190
- recurseRoutes(children);
1191
- }
1192
- });
1193
- };
1194
- recurseRoutes([routeTree]);
1195
- const scoredRoutes = [];
1196
- const routes = Object.values(routesById);
1197
- routes.forEach((d, i) => {
1198
- var _a;
1199
- if (d.isRoot || !d.path) {
1200
- return;
1201
- }
1202
- const trimmed = trimPathLeft(d.fullPath);
1203
- let parsed = parsePathname(trimmed);
1204
- let skip = 0;
1205
- while (parsed.length > skip + 1 && ((_a = parsed[skip]) == null ? void 0 : _a.value) === "/") {
1206
- skip++;
1207
- }
1208
- if (skip > 0) parsed = parsed.slice(skip);
1209
- let optionalParamCount = 0;
1210
- let hasStaticAfter = false;
1211
- const scores = parsed.map((segment, index) => {
1212
- if (segment.value === "/") {
1213
- return 0.75;
1214
- }
1215
- let baseScore = void 0;
1216
- if (segment.type === SEGMENT_TYPE_PARAM) {
1217
- baseScore = REQUIRED_PARAM_BASE_SCORE;
1218
- } else if (segment.type === SEGMENT_TYPE_OPTIONAL_PARAM) {
1219
- baseScore = OPTIONAL_PARAM_BASE_SCORE;
1220
- optionalParamCount++;
1221
- } else if (segment.type === SEGMENT_TYPE_WILDCARD) {
1222
- baseScore = WILDCARD_PARAM_BASE_SCORE;
1223
- }
1224
- if (baseScore) {
1225
- for (let i2 = index + 1; i2 < parsed.length; i2++) {
1226
- const nextSegment = parsed[i2];
1227
- if (nextSegment.type === SEGMENT_TYPE_PATHNAME && nextSegment.value !== "/") {
1228
- hasStaticAfter = true;
1229
- return handleParam(segment, baseScore + 0.2);
1230
- }
1231
- }
1232
- return handleParam(segment, baseScore);
1233
- }
1234
- return 1;
1235
- });
1236
- scoredRoutes.push({
1237
- child: d,
1238
- trimmed,
1239
- parsed,
1240
- index: i,
1241
- scores,
1242
- optionalParamCount,
1243
- hasStaticAfter
1244
- });
1245
- });
1246
- const flatRoutes = scoredRoutes.sort((a, b) => {
1247
- const minLength = Math.min(a.scores.length, b.scores.length);
1248
- for (let i = 0; i < minLength; i++) {
1249
- if (a.scores[i] !== b.scores[i]) {
1250
- return b.scores[i] - a.scores[i];
1251
- }
1252
- }
1253
- if (a.scores.length !== b.scores.length) {
1254
- if (a.optionalParamCount !== b.optionalParamCount) {
1255
- if (a.hasStaticAfter === b.hasStaticAfter) {
1256
- return a.optionalParamCount - b.optionalParamCount;
1257
- } else if (a.hasStaticAfter && !b.hasStaticAfter) {
1258
- return -1;
1259
- } else if (!a.hasStaticAfter && b.hasStaticAfter) {
1260
- return 1;
1261
- }
1262
- }
1263
- return b.scores.length - a.scores.length;
1264
- }
1265
- for (let i = 0; i < minLength; i++) {
1266
- if (a.parsed[i].value !== b.parsed[i].value) {
1267
- return a.parsed[i].value > b.parsed[i].value ? 1 : -1;
1268
- }
1269
- }
1270
- return a.index - b.index;
1271
- }).map((d, i) => {
1272
- d.child.rank = i;
1273
- return d.child;
1274
- });
1275
- return { routesById, routesByPath, flatRoutes };
1276
- }
1277
1147
  function getMatchedRoutes({
1278
1148
  pathname,
1279
1149
  routePathname,
@@ -1420,7 +1290,6 @@ export {
1420
1290
  getInitialRouterState,
1421
1291
  getLocationChangeInfo,
1422
1292
  getMatchedRoutes,
1423
- lazyFn,
1424
- processRouteTree
1293
+ lazyFn
1425
1294
  };
1426
1295
  //# sourceMappingURL=router.js.map