UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

99 lines 3.01 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var sortRoutes_exports = {}; __export(sortRoutes_exports, { sortRoutes: () => sortRoutes, sortRoutesWithInitial: () => sortRoutesWithInitial }); module.exports = __toCommonJS(sortRoutes_exports); var import_matchers = require("./matchers.cjs"); function sortDynamicConvention(a, b) { if (a.deep && !b.deep) { return 1; } if (!a.deep && b.deep) { return -1; } return 0; } function sortRoutes(a, b) { const aDynamicSegments = getDynamicSegments(a); const bDynamicSegments = getDynamicSegments(b); if (aDynamicSegments.length && !bDynamicSegments.length) { return 1; } if (!aDynamicSegments.length && bDynamicSegments.length) { return -1; } if (aDynamicSegments.length && bDynamicSegments.length) { if (aDynamicSegments.length !== bDynamicSegments.length) { return bDynamicSegments.length - aDynamicSegments.length; } for (let i = 0; i < aDynamicSegments.length; i++) { const aDynamic = aDynamicSegments[i]; const bDynamic = bDynamicSegments[i]; if (aDynamic.notFound && bDynamic.notFound) { const s2 = sortDynamicConvention(aDynamic, bDynamic); if (s2) { return s2; } } if (aDynamic.notFound && !bDynamic.notFound) { return 1; } if (!aDynamic.notFound && bDynamic.notFound) { return -1; } const s = sortDynamicConvention(aDynamic, bDynamic); if (s) { return s; } } return 0; } const aIndex = a.route === "index" || (0, import_matchers.matchGroupName)(a.route) != null; const bIndex = b.route === "index" || (0, import_matchers.matchGroupName)(b.route) != null; if (aIndex && !bIndex) { return -1; } if (!aIndex && bIndex) { return 1; } return a.route.length - b.route.length; } function getDynamicSegments(route) { return [...(route.dynamic || []), ...(route.layouts?.flatMap(layout => layout.dynamic || []) || [])]; } function sortRoutesWithInitial(initialRouteName) { return (a, b) => { if (initialRouteName) { if (a.route === initialRouteName) { return -1; } if (b.route === initialRouteName) { return 1; } } return sortRoutes(a, b); }; }