{"version":3,"file":"weekStart.mjs","names":[],"sources":["../../../../package/common/utils/weekStart.ts"],"sourcesContent":["/** A day of the week, as `Date#getDay()` counts: 0 is Sunday, 1 is Monday. */\nexport type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ntype WeekInfoLocale = Intl.Locale & {\n  getWeekInfo?: () => { firstDay: number };\n  /** The accessor form Chrome 99 to 129 and Safari 15.4 to 16 shipped before the method. */\n  weekInfo?: { firstDay: number };\n};\n\nconst weekStarts = new Map<string, Weekday>();\n\n/**\n * The locale's first day of the week, falling back to Monday where `getWeekInfo` is missing:\n * it is Baseline only since July 2026 (Chrome 130, Firefox 153, Safari 17).\n */\nexport function localeWeekStart(locale: string | undefined): Weekday {\n  const key = locale ?? '';\n  const cached = weekStarts.get(key);\n  if (cached !== undefined) return cached;\n\n  let result: Weekday = 1;\n  try {\n    const tag = locale ?? new Intl.DateTimeFormat().resolvedOptions().locale;\n    const info = new Intl.Locale(tag) as WeekInfoLocale;\n    const weekInfo = info.getWeekInfo?.() ?? info.weekInfo;\n    // `firstDay` counts 1 (Monday) to 7 (Sunday); `getDay()` counts 0 (Sunday) to 6.\n    if (weekInfo) result = (weekInfo.firstDay % 7) as Weekday;\n  } catch {\n    // An invalid tag: Intl.DateTimeFormat would have thrown for it too, so keep the fallback.\n  }\n  weekStarts.set(key, result);\n  return result;\n}\n"],"mappings":"aASA,IAAM,EAAa,IAAI,IAMvB,SAAgB,EAAgB,EAAqC,CACnE,IAAM,EAAM,GAAU,GAChB,EAAS,EAAW,IAAI,CAAG,EACjC,GAAI,IAAW,IAAA,GAAW,OAAO,EAEjC,IAAI,EAAkB,EACtB,GAAI,CACF,IAAM,EAAM,GAAU,IAAI,KAAK,eAAe,CAAC,CAAC,gBAAgB,CAAC,CAAC,OAC5D,EAAO,IAAI,KAAK,OAAO,CAAG,EAC1B,EAAW,EAAK,cAAc,GAAK,EAAK,SAE1C,IAAU,EAAU,EAAS,SAAW,EAC9C,MAAQ,CAER,CAEA,OADA,EAAW,IAAI,EAAK,CAAM,EACnB,CACT"}