one
Version:
One is a new React Framework that makes Vite serve both native and web.
118 lines • 4.27 kB
JavaScript
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: !0
});
},
__copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__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: !0
}), mod);
var matchers_exports = {};
__export(matchers_exports, {
getContextKey: () => getContextKey,
getNameFromFilePath: () => getNameFromFilePath,
hasInterceptPrefix: () => hasInterceptPrefix,
isSlotDirectory: () => isSlotDirectory,
isTypedRoute: () => isTypedRoute,
matchArrayGroupName: () => matchArrayGroupName,
matchDeepDynamicRouteName: () => matchDeepDynamicRouteName,
matchDynamicName: () => matchDynamicName,
matchGroupName: () => matchGroupName,
matchInterceptPrefix: () => matchInterceptPrefix,
matchSlotName: () => matchSlotName,
removeFileSystemDots: () => removeFileSystemDots,
removeSupportedExtensions: () => removeSupportedExtensions,
stripGroupSegmentsFromPath: () => stripGroupSegmentsFromPath,
stripInterceptPrefix: () => stripInterceptPrefix,
stripInvisibleSegmentsFromPath: () => stripInvisibleSegmentsFromPath,
stripSlotSegmentsFromPath: () => stripSlotSegmentsFromPath,
testNotFound: () => testNotFound
});
module.exports = __toCommonJS(matchers_exports);
const dynamicNameRe = /^\[([^[\]]+?)\]$/;
function matchDynamicName(name) {
const paramName = name.match(dynamicNameRe)?.[1];
if (paramName != null) return paramName.startsWith("...") ? {
name: paramName.slice(3),
deep: !0
} : {
name: paramName,
deep: !1
};
}
function matchDeepDynamicRouteName(name) {
return name.match(/^\[\.\.\.([^/]+?)\]$/)?.[1];
}
function testNotFound(name) {
return name.endsWith("+not-found");
}
function matchGroupName(name) {
return name.match(/^(?:[^\\(\\)])*?\(([^\\/]+)\).*?$/)?.[1];
}
function matchArrayGroupName(name) {
return name.match(/(?:[^\\(\\)])*?\(?([^\\/()]+,[^\\/()]+)\)?.*?$/)?.[1];
}
function getNameFromFilePath(name) {
return removeSupportedExtensions(removeFileSystemDots(name));
}
function getContextKey(name) {
const normal = "/" + getNameFromFilePath(name);
return normal.endsWith("_layout") ? normal.replace(/\/?_layout$/, "") : normal;
}
function removeSupportedExtensions(name) {
return name.replace(/(\+(api|spa|ssg|ssr))?\.[jt]sx?$/g, "");
}
function removeFileSystemDots(filePath) {
return filePath.replace(/^(?:\.\.?\/)+/g, "");
}
function stripGroupSegmentsFromPath(path) {
return path.split("/").reduce((acc, v) => (matchGroupName(v) == null && acc.push(v), acc), []).join("/");
}
function stripInvisibleSegmentsFromPath(path) {
return stripGroupSegmentsFromPath(path).replace(/\/?index$/, "");
}
function isTypedRoute(name) {
return !name.startsWith("+") && !name.endsWith(".d.ts") && name.match(/(_layout|[^/]*?\+[^/]*?)\.[tj]sx?$/) === null;
}
const slotPrefixRe = /^@([a-zA-Z][a-zA-Z0-9_-]*)$/;
function matchSlotName(name) {
return name.match(slotPrefixRe)?.[1];
}
function isSlotDirectory(name) {
return slotPrefixRe.test(name);
}
function matchInterceptPrefix(segment) {
const match = segment.match(/^((?:\(\.{1,3}\))+)(.+)$/);
if (!match) return;
const [, prefixes, targetPath] = match;
return prefixes.includes("(...)") ? {
levels: 1 / 0,
targetPath,
originalSegment: segment
} : {
levels: (prefixes.match(/\(\.{2}\)/g) || []).length,
targetPath,
originalSegment: segment
};
}
function stripInterceptPrefix(segment) {
const match = matchInterceptPrefix(segment);
return match ? match.targetPath : segment;
}
function hasInterceptPrefix(segment) {
return /^\(\.{1,3}\)/.test(segment);
}
function stripSlotSegmentsFromPath(path) {
return path.split("/").filter(segment => !isSlotDirectory(segment)).join("/");
}