{"version":3,"file":"timing.cjs","names":[],"sources":["../../src/utils/timing.ts"],"sourcesContent":["interface Timer {\n  description?: string;\n  start: number;\n}\n\nexport interface Options {\n  enabled: boolean;\n  crossOrigin?: string;\n}\n\nexport function timing(options: Options = { enabled: true }) {\n  const { enabled, crossOrigin } = options;\n  let start = performance.now();\n  const headers: string[] = [];\n  const timers = new Map<string, Timer>();\n\n  return {\n    startTime: (name: Lowercase<string>, description?: string) => {\n      timers.set(name, { description, start: performance.now() });\n    },\n    endTime: (name: Lowercase<string>, precision?: number) => {\n      const timer = timers.get(name);\n      if (!timer) {\n        console.warn(`timing: ${name} not found`);\n        return;\n      }\n      const { start, description } = timer;\n      const dur = (performance.now() - start).toFixed(precision ?? 1);\n      timers.delete(name);\n      const metric = description\n        ? `${name};dur=${dur};desc=\"${description}\"`\n        : `${name};dur=${dur}`;\n      headers.push(metric);\n    },\n    mark: (name: Lowercase<string>, description?: string, precision?: number) => {\n      const dur = (performance.now() - start).toFixed(precision ?? 1);\n      const metric = description\n        ? `${name};dur=${dur};desc=\"${description}\"`\n        : `${name};dur=${dur}`;\n      headers.push(metric);\n      start = performance.now();\n    },\n    setMetric: (\n      name: Lowercase<string>,\n      value: number | string | undefined,\n      description?: string,\n      precision?: number\n    ) => {\n      if (typeof value === 'number') {\n        const dur = value.toFixed(precision ?? 1);\n        const metric = description\n          ? `${name};dur=${dur};desc=\"${description}\"`\n          : `${name};dur=${dur}`;\n        headers.push(metric);\n      } else {\n        const metric = value ? `${name};desc=\"${value}\"` : name;\n        headers.push(metric);\n      }\n    },\n    setTiming: (response: Response) => {\n      if (!enabled) return;\n      response.headers.append('Server-Timing', headers.join(','));\n      response.headers.append('Timing-Allow-Origin', crossOrigin ?? '*');\n    },\n  };\n}\n"],"mappings":";;AAUA,SAAgB,OAAO,UAAmB,EAAE,SAAS,KAAK,GAAG;CAC3D,MAAM,EAAE,SAAS,gBAAgB;CACjC,IAAI,QAAQ,YAAY,IAAI;CAC5B,MAAM,UAAoB,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