/** * Initials for a name. * * 'Jane Smith' -> 'JS' first and last word * 'Jane Q. Public' -> 'JP' * 'Madonna' -> 'M' one word, one letter * 'jane.smith@example.com' -> 'JS' the part before the @, split on . _ - + * 'Jean-Luc Picard' -> 'JP' * 'Łukasz Żuk' -> 'ŁŻ' * '王小明' -> '王' * '', null, ' !! ' -> '' nothing to go on: callers show an icon * * Words are split on spaces, dots, underscores, hyphens and plus signs; * anything that is not a letter or digit at the start of a word (quotes, * brackets, emoji) is skipped, and bracketed notes like "(Admin)" are dropped. * @param {string|null|undefined} name * @returns {string} */ export function avatarInitials(name: string | null | undefined): string; /** * The tone (0-7) for a name: FNV-1a over the trimmed, lower-cased, single-spaced * name. Stable across pages, sessions and machines; case and spacing do not * change it, so 'jane smith' and 'Jane Smith' match. * @param {string} key * @returns {number} */ export function avatarTone(key: string): number; /** * Render one avatar. * @overload * @param {string|Element|ArrayLike|null} target * @param {AvatarOptions} [options] * @returns {AvatarHandle|null} */ export function avatar(target: string | Element | ArrayLike | null, options?: AvatarOptions | undefined): AvatarHandle | null; /** * Render one avatar into a detached for you to insert. * @overload * @param {AvatarOptions} options * @returns {AvatarHandle} */ export function avatar(options: AvatarOptions): AvatarHandle; export namespace avatar { export { avatarInitials as initials }; export { avatarTone as tone }; /** * The live handle on an element, if any - the same answer as E.get(target, 'avatar'). * @param {string|Element|ArrayLike} target * @returns {AvatarHandle|null} */ export function get(target: string | Element | ArrayLike): AvatarHandle | null; /** * Turn every `[data-avatar]` under `root` (and `root` itself) into an avatar, * once. Options come from `data-avatar-*`. Returns the new handles. * @param {string|Element|Document} [root] * @returns {AvatarHandle[]} */ export function scan(root?: string | Element | Document): AvatarHandle[]; } /** * Render a stack of avatars with a "+N" overflow bubble. * * @param {string|Element|ArrayLike} target - a
    /
      to fill, or any element * to put a new
        into (its content comes back on destroy()) * @param {AvatarGroupOptions} [options] - see GROUP_DEFAULTS * @returns {AvatarGroupHandle|null} null if nothing matched */ export function avatarGroup(target: string | Element | ArrayLike, options?: AvatarGroupOptions): AvatarGroupHandle | null; export namespace avatarGroup { /** * The live group handle on a host element (or its list), if any - the same answer as E.get(target, 'avatar-group'). * @param {string|Element|ArrayLike} target * @returns {AvatarGroupHandle|null} */ function get(target: string | Element | ArrayLike): AvatarGroupHandle | null; } /** @type {AvatarSize[]} */ export const AVATAR_SIZES: AvatarSize[]; /** @type {AvatarShape[]} */ export const AVATAR_SHAPES: AvatarShape[]; /** @type {AvatarStatus[]} */ export const AVATAR_STATUSES: AvatarStatus[]; /** How many `.avatar-tone-*` classes elements.css defines. */ export const AVATAR_TONES: 8; export default avatar; export type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl"; export type AvatarShape = "circle" | "rounded" | "square"; export type AvatarStatus = "online" | "away" | "busy" | "offline"; export type AvatarOptions = { /** * - The person: initials, tone and accessible name come from it */ name?: string | null | undefined; /** * - Picture URL; falls back to the initials (or icon) if it fails to load */ src?: string | null | undefined; /** * - Accessible name when it should differ from name */ alt?: string | null | undefined; /** * - Size (default 'md') */ size?: AvatarSize | undefined; /** * - Shape (default 'circle') */ shape?: AvatarShape | undefined; /** * - Status dot; the word goes into the accessible name */ status?: AvatarStatus | null | undefined; /** * - Words for the statuses in the accessible name, e.g. {busy: 'in a meeting'} */ statusLabels?: Partial> | null | undefined; /** * - Icon name shown instead of initials ('user' when there is no name) */ icon?: string | null | undefined; /** * - Hover text; true = the accessible name */ title?: string | true | null | undefined; /** * - A primary-coloured ring (default false) */ ring?: boolean | undefined; /** * - 0-7 to choose the tint; default is a hash of the name */ tone?: number | null | undefined; /** * - aria-hidden: the name is written next to it (default false) */ decorative?: boolean | undefined; }; /** * The handle E.avatar() returns. `options`, `initials`, `tone` and `label` are read only. */ export type AvatarHandle = { /** * - The avatar element */ element: HTMLElement; /** * - The options in force */ options: AvatarOptions; /** * - The initials drawn ('' when an icon is shown) */ initials: string; /** * - The tone 0-7, or null with nothing to hash */ tone: number | null; /** * - The accessible name, e.g. 'Jane Smith (online)' */ label: string; /** * - Merge options and redraw */ update: (options?: AvatarOptions) => AvatarHandle; /** * - Restore the element's previous children, classes and attributes */ destroy: () => HTMLElement; }; /** * `E.avatar` - the factory with `initials`, `tone`, `get` and `scan`. */ export type AvatarStatic = typeof avatar; /** * One person in an avatar group. */ export type AvatarPerson = { name?: string | undefined; src?: string | undefined; status?: AvatarStatus | undefined; /** * - Makes the avatar a link */ href?: string | undefined; alt?: string | undefined; icon?: string | undefined; tone?: number | undefined; /** * - Hover text (default: the accessible name) */ title?: string | true | undefined; }; export type AvatarGroupOptions = { /** * - People, or plain names */ people?: (string | AvatarPerson)[] | undefined; /** * - Show this many, then "+N"; null = everyone */ max?: number | null | undefined; /** * - Size (default 'md') */ size?: AvatarSize | undefined; /** * - Shape (default 'circle') */ shape?: AvatarShape | undefined; /** * - 'none' | 'sm' | 'md' | 'lg', pixels, or any CSS length; null = the stylesheet's 25% */ overlap?: string | number | null | undefined; /** * - Accessible name for the list */ label?: string | null | undefined; statusLabels?: Partial> | null | undefined; /** * - Called when "+N" is pressed, instead of the popover */ onMore?: ((hidden: AvatarPerson[], event: MouseEvent) => void) | null | undefined; /** * - false: no popover, the hidden names go in the button's title (default true) */ popover?: boolean | undefined; /** * - The "+N" button's accessible name (default '3 more: A, B and C') */ moreLabel?: ((count: number, names: string[]) => string) | null | undefined; }; /** * The handle E.avatarGroup() returns. Everything but the methods is read only. */ export type AvatarGroupHandle = { /** * - The
          */ element: HTMLUListElement | HTMLOListElement; options: AvatarGroupOptions; people: AvatarPerson[]; /** * - Drawn as avatars */ shown: AvatarPerson[]; /** * - Folded into "+N" */ hidden: AvatarPerson[]; /** * - The "+N" button, or null */ more: HTMLButtonElement | null; /** * - The "+N" popover, or null */ popover: import("./popover.js").PopoverInstance | null; update: (options?: AvatarGroupOptions) => AvatarGroupHandle; setPeople: (people: Array) => AvatarGroupHandle; /** * - Remove everything and restore the host */ destroy: () => HTMLElement; }; /** * `E.avatarGroup` - the factory with `get`. */ export type AvatarGroupStatic = typeof avatarGroup;