one
Version:
One is a new React Framework that makes Vite serve both native and web.
191 lines (189 loc) • 6.26 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: 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 matchers_exports = {};
__export(matchers_exports, {
getContextKey: () => getContextKey,
getNameFromFilePath: () => getNameFromFilePath,
hasInterceptPrefix: () => hasInterceptPrefix,
isSlotDirectory: () => isSlotDirectory,
isTypedRoute: () => isTypedRoute,
matchArrayGroupName: () => matchArrayGroupName,
matchDeepDynamicRouteName: () => matchDeepDynamicRouteName,
matchDirectoryRenderMode: () => matchDirectoryRenderMode,
matchDynamicName: () => matchDynamicName,
matchGroupName: () => matchGroupName,
matchInterceptPrefix: () => matchInterceptPrefix,
matchRoutePattern: () => matchRoutePattern,
matchSlotName: () => matchSlotName,
removeFileSystemDots: () => removeFileSystemDots,
removeSupportedExtensions: () => removeSupportedExtensions,
stripGroupSegmentsFromPath: () => stripGroupSegmentsFromPath,
stripInterceptPrefix: () => stripInterceptPrefix,
stripInvisibleSegmentsFromPath: () => stripInvisibleSegmentsFromPath,
stripSlotSegmentsFromPath: () => stripSlotSegmentsFromPath,
testNotFound: () => testNotFound
});
module.exports = __toCommonJS(matchers_exports);
var dynamicNameRe = /^\[([^[\]]+?)\]$/;
function matchDynamicName(name) {
var _name_match;
var paramName = (_name_match = name.match(dynamicNameRe)) === null || _name_match === void 0 ? void 0 : _name_match[1];
if (paramName == null) {
return void 0;
} else if (paramName.startsWith("...")) {
return {
name: paramName.slice(3),
deep: true
};
} else {
return {
name: paramName,
deep: false
};
}
}
function matchRoutePattern(pattern, path) {
var patternSegments = pattern.split("/").filter(Boolean);
if (patternSegments[patternSegments.length - 1] === "index") {
patternSegments.pop();
}
var pathSegments = path.split("/").filter(Boolean);
var specificity = 0;
var pi = 0;
for (var ui = 0; ui < patternSegments.length; ui++) {
var seg = patternSegments[ui];
if (seg.startsWith("(") && seg.endsWith(")")) continue;
if (seg.startsWith("[...") && seg.endsWith("]")) {
return {
specificity: specificity + (pathSegments.length - pi)
};
}
if (pi >= pathSegments.length) return null;
if (seg.startsWith("[") && seg.endsWith("]")) {
specificity += 1;
pi += 1;
continue;
}
if (seg !== pathSegments[pi]) return null;
specificity += 2;
pi += 1;
}
return {
specificity
};
}
function matchDeepDynamicRouteName(name) {
var _name_match;
return (_name_match = name.match(/^\[\.\.\.([^/]+?)\]$/)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function testNotFound(name) {
return name.endsWith("+not-found");
}
function matchGroupName(name) {
var _name_match;
return (_name_match = name.match(/^(?:[^\\(\\)])*?\(([^\\/]+)\).*?$/)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function matchArrayGroupName(name) {
var _name_match;
return (_name_match = name.match(/(?:[^\\(\\)])*?\(?([^\\/()]+,[^\\/()]+)\)?.*?$/)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function getNameFromFilePath(name) {
return removeSupportedExtensions(removeFileSystemDots(name));
}
function getContextKey(name) {
var normal = "/" + getNameFromFilePath(name);
if (!normal.endsWith("_layout")) {
return normal;
}
return normal.replace(/\/?_layout$/, "");
}
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(function (acc, v) {
if (matchGroupName(v) == null) {
acc.push(v);
}
return 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;
}
var directoryRenderModeRe = /^(.+)\+(api|ssg|ssr|spa)$/;
function matchDirectoryRenderMode(name) {
var match = name.match(directoryRenderModeRe);
if (!match) return void 0;
return {
name: match[1],
renderMode: match[2]
};
}
var slotPrefixRe = /^@([a-zA-Z][a-zA-Z0-9_-]*)$/;
function matchSlotName(name) {
var _name_match;
return (_name_match = name.match(slotPrefixRe)) === null || _name_match === void 0 ? void 0 : _name_match[1];
}
function isSlotDirectory(name) {
return slotPrefixRe.test(name);
}
function matchInterceptPrefix(segment) {
var match = segment.match(/^((?:\(\.{1,3}\))+)(.+)$/);
if (!match) return void 0;
var [, prefixes, targetPath] = match;
if (prefixes.includes("(...)")) {
return {
levels: Infinity,
targetPath,
originalSegment: segment
};
}
var doubleDotMatches = prefixes.match(/\(\.{2}\)/g) || [];
var levels = doubleDotMatches.length;
return {
levels,
targetPath,
originalSegment: segment
};
}
function stripInterceptPrefix(segment) {
var match = matchInterceptPrefix(segment);
return match ? match.targetPath : segment;
}
function hasInterceptPrefix(segment) {
return /^\(\.{1,3}\)/.test(segment);
}
function stripSlotSegmentsFromPath(path) {
return path.split("/").filter(function (segment) {
return !isSlotDirectory(segment);
}).join("/");
}
//# sourceMappingURL=matchers.native.js.map