{"version":3,"file":"accessibleLabel.mjs","names":[],"sources":["../../../src/a11y/accessibleLabel.ts"],"sourcesContent":["import type { TranslationContextValue } from '../context/TranslationContext';\n\n/** Produces one segment of a composed accessible name; return `undefined`/empty to omit it. */\nexport type AccessibleLabelPart<TData> = (data: TData) => string | undefined;\n\n/** Customization for a part-composed accessible name. */\nexport type AccessibleLabelConfig<TData> = {\n  /** Returns the entire label; `order`, `parts` and `separator` are then ignored. */\n  build?: (data: TData) => string;\n  /** Which parts to include, in what order. A part not listed here is never rendered. */\n  order?: ReadonlyArray<string>;\n  /** Override or add individual part generators; merged over the defaults. */\n  parts?: Record<string, AccessibleLabelPart<TData>>;\n  /** Joiner between non-empty parts. Defaults to \". \". */\n  separator?: string;\n};\n\n/**\n * Composes an accessible name from named parts, joining the non-empty segments with\n * `config.separator`. `config.build` replaces the whole label; `config.parts` merge over\n * `defaultParts`.\n */\nexport const composeAccessibleLabel = <TData>(\n  data: TData,\n  defaultParts: Record<string, AccessibleLabelPart<TData>>,\n  defaultOrder: ReadonlyArray<string>,\n  config: AccessibleLabelConfig<TData> = {},\n): string => {\n  if (config.build) return config.build(data);\n  const parts: Record<string, AccessibleLabelPart<TData>> = {\n    ...defaultParts,\n    ...config.parts,\n  };\n  const order = config.order ?? defaultOrder;\n  return order\n    .map((key) => parts[key]?.(data))\n    .filter((value): value is string => !!value)\n    .join(config.separator ?? '. ');\n};\n\n// Label parts shared by several list rows. Each is typed over only the data it reads, so parameter\n// contravariance makes it assignable to the wider per-row part types.\ntype WithT = { t: TranslationContextValue['t'] };\n\n/**\n * Announces the active (currently open) row in its name, because `aria-selected` alone is not\n * reliably spoken for an option with a custom name.\n */\nexport const activeLabelPart: AccessibleLabelPart<WithT & { active?: boolean }> = ({\n  active,\n  t,\n}) => (active ? t('a11y.accessibleLabel.active.ariaLabel', 'Active') : undefined);\n\n/** Announces the unread count when there is one. */\nexport const unreadCountLabelPart: AccessibleLabelPart<\n  WithT & { unreadCount?: number }\n> = ({ t, unreadCount }) =>\n  typeof unreadCount === 'number' && unreadCount > 0\n    ? t('a11y.accessibleLabel.unreadMessage.ariaLabel', {\n        count: unreadCount,\n        defaultValue_one: '{{ count }} unread message',\n        defaultValue_other: '{{ count }} unread messages',\n      })\n    : undefined;\n"],"mappings":";;;;;;AAsBA,IAAa,0BACX,MACA,cACA,cACA,SAAuC,CAAC,MAC7B;CACX,IAAI,OAAO,OAAO,OAAO,OAAO,MAAM,IAAI;CAC1C,MAAM,QAAoD;EACxD,GAAG;EACH,GAAG,OAAO;CACZ;CAEA,QADc,OAAO,SAAS,aAAA,CAE3B,KAAK,QAAQ,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAChC,QAAQ,UAA2B,CAAC,CAAC,KAAK,CAAC,CAC3C,KAAK,OAAO,aAAa,IAAI;AAClC;;;;;AAUA,IAAa,mBAAsE,EACjF,QACA,QACK,SAAS,EAAE,yCAAyC,QAAQ,IAAI,KAAA;;AAGvE,IAAa,wBAER,EAAE,GAAG,kBACR,OAAO,gBAAgB,YAAY,cAAc,IAC7C,EAAE,gDAAgD;CAChD,OAAO;CACP,kBAAkB;CAClB,oBAAoB;AACtB,CAAC,IACD,KAAA"}