{"version":3,"file":"startVueRouterView.mjs","names":[],"sources":["../../../src/domain/router/startVueRouterView.ts"],"sourcesContent":["import { display } from '@datadog/browser-core'\nimport type { RouteLocationMatched } from 'vue-router'\nimport { onRumInit } from '../vuePlugin'\n\nexport function startVueRouterView(matched: RouteLocationMatched[], path: string) {\n  onRumInit((configuration, rumPublicApi) => {\n    if (!configuration.router) {\n      display.warn('`router: true` is missing from the vue plugin configuration, the view will not be tracked.')\n      return\n    }\n    rumPublicApi.startView(computeViewName(matched, path))\n  })\n}\n\nexport function computeViewName(matched: RouteLocationMatched[], path: string): string {\n  if (!matched || matched.length === 0) {\n    return ''\n  }\n\n  let viewName = '/'\n\n  for (const routeRecord of matched) {\n    const routePath = routeRecord.path\n    if (!routePath) {\n      continue\n    }\n\n    // Note: Vue Router normalizes all paths in the matched array to absolute paths,\n    // so the relative-path branch below is purely defensive and not expected to be\n    // hit in practice. It mirrors the React Router implementation for consistency.\n    if (routePath.startsWith('/')) {\n      viewName = routePath\n    } else {\n      if (!viewName.endsWith('/')) {\n        viewName += '/'\n      }\n      viewName += routePath\n    }\n  }\n\n  return substituteCatchAll(viewName, path)\n}\n\n/**\n * Vue Router catch-all routes use `/:pathMatch(.*)*` instead of bare `*` like React Router.\n * Keeping the raw pattern as the view name isn't helpful, it hides information about which\n * path was actually visited. This function replaces only the catch-all segment with the\n * corresponding portion of the actual URL path, preserving any parameterized segments that\n * precede it. This aligns with how the React integration substitutes splats.\n *\n * We match the full `/:pathMatch(.*)*` pattern rather than just `:pathMatch(` to avoid\n * false positives on custom regex params (e.g. `/:pathMatch([a-z]+)`).\n *\n * @example\n * substituteCatchAll('/:pathMatch(.*)*', '/unknown/page') // => '/unknown/page'\n * substituteCatchAll('/org/:orgId/:pathMatch(.*)*', '/org/123/some/page') // => '/org/:orgId/some/page'\n */\nfunction substituteCatchAll(viewName: string, path: string): string {\n  const catchAllIndex = viewName.indexOf('/:pathMatch(.*)*')\n  if (catchAllIndex === -1) {\n    return viewName\n  }\n\n  // Keep parameterized segments before the catch-all intact\n  const prefix = viewName.substring(0, catchAllIndex)\n\n  // Count the number of path segments in the prefix to find the matching point in the actual path\n  const prefixSegmentCount = prefix === '' ? 0 : prefix.split('/').length - 1\n  const pathSegments = path.split('/')\n  const suffix = pathSegments.slice(prefixSegmentCount + 1).join('/')\n\n  return prefix + (suffix ? `/${suffix}` : '') || '/'\n}\n"],"mappings":";;;AAIA,SAAgB,mBAAmB,SAAiC,MAAc;CAChF,WAAW,eAAe,iBAAiB;EACzC,IAAI,CAAC,cAAc,QAAQ;GACzB,QAAQ,KAAK,4FAA4F;GACzG;EACF;EACA,aAAa,UAAU,gBAAgB,SAAS,IAAI,CAAC;CACvD,CAAC;AACH;AAEA,SAAgB,gBAAgB,SAAiC,MAAsB;CACrF,IAAI,CAAC,WAAW,QAAQ,WAAW,GACjC,OAAO;CAGT,IAAI,WAAW;CAEf,KAAK,MAAM,eAAe,SAAS;EACjC,MAAM,YAAY,YAAY;EAC9B,IAAI,CAAC,WACH;EAMF,IAAI,UAAU,WAAW,GAAG,GAC1B,WAAW;OACN;GACL,IAAI,CAAC,SAAS,SAAS,GAAG,GACxB,YAAY;GAEd,YAAY;EACd;CACF;CAEA,OAAO,mBAAmB,UAAU,IAAI;AAC1C;;;;;;;;;;;;;;;AAgBA,SAAS,mBAAmB,UAAkB,MAAsB;CAClE,MAAM,gBAAgB,SAAS,QAAQ,kBAAkB;CACzD,IAAI,kBAAkB,IACpB,OAAO;CAIT,MAAM,SAAS,SAAS,UAAU,GAAG,aAAa;CAGlD,MAAM,qBAAqB,WAAW,KAAK,IAAI,OAAO,MAAM,GAAG,CAAC,CAAC,SAAS;CAE1E,MAAM,SADe,KAAK,MAAM,GACN,CAAC,CAAC,MAAM,qBAAqB,CAAC,CAAC,CAAC,KAAK,GAAG;CAElE,OAAO,UAAU,SAAS,IAAI,WAAW,OAAO;AAClD"}