{"version":3,"file":"matchers.js","names":[],"sources":["esm/router/matchers.js"],"sourcesContent":["const dynamicNameRe = /^\\[([^[\\]]+?)\\]$/;\nfunction matchDynamicName(name) {\n  const paramName = name.match(dynamicNameRe)?.[1];\n  if (paramName == null) {\n    return void 0;\n  } else if (paramName.startsWith(\"...\")) {\n    return { name: paramName.slice(3), deep: true };\n  } else {\n    return { name: paramName, deep: false };\n  }\n}\nfunction matchRoutePattern(pattern, path) {\n  const patternSegments = pattern.split(\"/\").filter(Boolean);\n  if (patternSegments[patternSegments.length - 1] === \"index\") {\n    patternSegments.pop();\n  }\n  const pathSegments = path.split(\"/\").filter(Boolean);\n  let specificity = 0;\n  let pi = 0;\n  for (let ui = 0; ui < patternSegments.length; ui++) {\n    const seg = patternSegments[ui];\n    if (seg.startsWith(\"(\") && seg.endsWith(\")\")) continue;\n    if (seg.startsWith(\"[...\") && seg.endsWith(\"]\")) {\n      return { specificity: specificity + (pathSegments.length - pi) };\n    }\n    if (pi >= pathSegments.length) return null;\n    if (seg.startsWith(\"[\") && seg.endsWith(\"]\")) {\n      specificity += 1;\n      pi += 1;\n      continue;\n    }\n    if (seg !== pathSegments[pi]) return null;\n    specificity += 2;\n    pi += 1;\n  }\n  return { specificity };\n}\nfunction matchDeepDynamicRouteName(name) {\n  return name.match(/^\\[\\.\\.\\.([^/]+?)\\]$/)?.[1];\n}\nfunction testNotFound(name) {\n  return name.endsWith(\"+not-found\");\n}\nfunction matchGroupName(name) {\n  return name.match(/^(?:[^\\\\(\\\\)])*?\\(([^\\\\/]+)\\).*?$/)?.[1];\n}\nfunction matchArrayGroupName(name) {\n  return name.match(/(?:[^\\\\(\\\\)])*?\\(?([^\\\\/()]+,[^\\\\/()]+)\\)?.*?$/)?.[1];\n}\nfunction getNameFromFilePath(name) {\n  return removeSupportedExtensions(removeFileSystemDots(name));\n}\nfunction getContextKey(name) {\n  const normal = \"/\" + getNameFromFilePath(name);\n  if (!normal.endsWith(\"_layout\")) {\n    return normal;\n  }\n  return normal.replace(/\\/?_layout$/, \"\");\n}\nfunction removeSupportedExtensions(name) {\n  return name.replace(/(\\+(api|spa|ssg|ssr))?\\.[jt]sx?$/g, \"\");\n}\nfunction removeFileSystemDots(filePath) {\n  return filePath.replace(/^(?:\\.\\.?\\/)+/g, \"\");\n}\nfunction stripGroupSegmentsFromPath(path) {\n  return path.split(\"/\").reduce((acc, v) => {\n    if (matchGroupName(v) == null) {\n      acc.push(v);\n    }\n    return acc;\n  }, []).join(\"/\");\n}\nfunction stripInvisibleSegmentsFromPath(path) {\n  return stripGroupSegmentsFromPath(path).replace(/\\/?index$/, \"\");\n}\nfunction isTypedRoute(name) {\n  return !name.startsWith(\"+\") && !name.endsWith(\".d.ts\") && name.match(/(_layout|[^/]*?\\+[^/]*?)\\.[tj]sx?$/) === null;\n}\nconst directoryRenderModeRe = /^(.+)\\+(api|ssg|ssr|spa)$/;\nfunction matchFileRenderMode(name) {\n  const mode = name.match(/\\+(api|ssg|ssr|spa)\\.(?:\\w+\\.)?[jt]sx?$/)?.[1];\n  if (mode === \"api\" || mode === \"ssg\" || mode === \"ssr\" || mode === \"spa\") {\n    return mode;\n  }\n}\nfunction matchDirectoryRenderMode(name) {\n  const match = name.match(directoryRenderModeRe);\n  if (!match) return void 0;\n  return {\n    name: match[1],\n    renderMode: match[2]\n  };\n}\nconst slotPrefixRe = /^@([a-zA-Z][a-zA-Z0-9_-]*)$/;\nfunction matchSlotName(name) {\n  return name.match(slotPrefixRe)?.[1];\n}\nfunction isSlotDirectory(name) {\n  return slotPrefixRe.test(name);\n}\nfunction matchInterceptPrefix(segment) {\n  const match = segment.match(/^((?:\\(\\.{1,3}\\))+)(.+)$/);\n  if (!match) return void 0;\n  const [, prefixes, targetPath] = match;\n  if (prefixes.includes(\"(...)\")) {\n    return { levels: Infinity, targetPath, originalSegment: segment };\n  }\n  const doubleDotMatches = prefixes.match(/\\(\\.{2}\\)/g) || [];\n  const levels = doubleDotMatches.length;\n  return { levels, targetPath, originalSegment: segment };\n}\nfunction stripInterceptPrefix(segment) {\n  const match = matchInterceptPrefix(segment);\n  return match ? match.targetPath : segment;\n}\nfunction hasInterceptPrefix(segment) {\n  return /^\\(\\.{1,3}\\)/.test(segment);\n}\nfunction stripSlotSegmentsFromPath(path) {\n  return path.split(\"/\").filter((segment) => !isSlotDirectory(segment)).join(\"/\");\n}\nexport {\n  getContextKey,\n  getNameFromFilePath,\n  hasInterceptPrefix,\n  isSlotDirectory,\n  isTypedRoute,\n  matchArrayGroupName,\n  matchDeepDynamicRouteName,\n  matchDirectoryRenderMode,\n  matchDynamicName,\n  matchFileRenderMode,\n  matchGroupName,\n  matchInterceptPrefix,\n  matchRoutePattern,\n  matchSlotName,\n  removeFileSystemDots,\n  removeSupportedExtensions,\n  stripGroupSegmentsFromPath,\n  stripInterceptPrefix,\n  stripInvisibleSegmentsFromPath,\n  stripSlotSegmentsFromPath,\n  testNotFound\n};\n//# sourceMappingURL=matchers.js.map\n"],"mappings":";AAAA,MAAM,gBAAgB;AACtB,SAAS,iBAAiB,MAAM;CAC9B,MAAM,YAAY,KAAK,MAAM,aAAa,CAAC,GAAG;CAC9C,IAAI,aAAa,MAAM;EACrB,OAAO,KAAK;CACd,OAAO,IAAI,UAAU,WAAW,KAAK,GAAG;EACtC,OAAO;GAAE,MAAM,UAAU,MAAM,CAAC;GAAG,MAAM;EAAK;CAChD,OAAO;EACL,OAAO;GAAE,MAAM;GAAW,MAAM;EAAM;CACxC;AACF;AACA,SAAS,kBAAkB,SAAS,MAAM;CACxC,MAAM,kBAAkB,QAAQ,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CACzD,IAAI,gBAAgB,gBAAgB,SAAS,OAAO,SAAS;EAC3D,gBAAgB,IAAI;CACtB;CACA,MAAM,eAAe,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CACnD,IAAI,cAAc;CAClB,IAAI,KAAK;CACT,KAAK,IAAI,KAAK,GAAG,KAAK,gBAAgB,QAAQ,MAAM;EAClD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