{"version":3,"sources":["../src/routeMatch.ts"],"sourcesContent":["import type { RouteParams } from './RoutingSpec';\n\n// from: https://stackoverflow.com/a/63838890\nconst escapeForRegexp = (str: string): string => str.replace(/[.*+\\-?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n// Internal group name standing in for a `*` wildcard (which is not a valid JS\n// regex group identifier); remapped to the `*` param key after matching.\nconst WILDCARD_GROUP = 'wild';\n\n/**\n * Compile a path template to an anchored RegExp with named groups:\n *   `:name` → one non-slash segment   `*` → the rest (greedy)\n * A template with neither token is a literal exact match. Raw RegExp patterns\n * never reach here — they are the escape hatch, used as authored.\n */\nexport const compileTemplate = (template: string): RegExp => {\n  const token = /(:[A-Za-z_][A-Za-z0-9_]*)|\\*/g;\n  let src = '';\n  let last = 0;\n  let m: RegExpExecArray | null;\n  while ((m = token.exec(template)) !== null) {\n    src += escapeForRegexp(template.slice(last, m.index));\n    src += m[1] ? `(?<${m[1].slice(1)}>[^/]+)` : `(?<${WILDCARD_GROUP}>.*)`;\n    last = m.index + m[0].length;\n  }\n  src += escapeForRegexp(template.slice(last));\n  return new RegExp(`^${src}$`);\n};\n\nconst templateCache = new Map<string, RegExp>();\n\n/** Resolve a pattern to a RegExp: templates are compiled (and cached), RegExp passes through. */\nexport const toRegExp = (pattern: string | RegExp): RegExp => {\n  if (pattern instanceof RegExp) {\n    return pattern;\n  }\n  let compiled = templateCache.get(pattern);\n  if (!compiled) {\n    compiled = compileTemplate(pattern);\n    templateCache.set(pattern, compiled);\n  }\n  return compiled;\n};\n\n/**\n * Match a `sandboxPath` against a route pattern. Returns the named params on a\n * match (the `*` wildcard surfaces under the `'*'` key), or `null` otherwise.\n */\nexport const matchRoute = (pattern: string | RegExp, path: string): RouteParams | null => {\n  const match = path.match(toRegExp(pattern));\n  if (!match) {\n    return null;\n  }\n  const params: RouteParams = {};\n  for (const [key, value] of Object.entries(match.groups ?? {})) {\n    if (value !== undefined) {\n      params[key === WILDCARD_GROUP ? '*' : key] = value;\n    }\n  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