/** * The usage panel. * * Layout is Codex's analytics **Overview** profile report, top to bottom: * * 1. a centred identity block — avatar, display name, handle; * 2. a five-cell bar of all-time headline figures; * 3. `Token activity`, a year-long contribution heatmap with a * daily / weekly / cumulative switch; * 4. a two-column footer of `Insights` and the most-used list. * * The numbers are localized, which matters more than it sounds: a Chinese UI * reads `3.7亿` and `5317.1万`, not `370M` and `53.17M`, and a duration is * `46分59秒`, not `46m 59s`. {@link localeCompact} and {@link localeDuration} * own that split so the layout never has to care. * * @module dsh-token-dashboard/client/panel */ import { type ReactNode } from 'react'; import type { UsageSnapshot } from '../shared/types.js'; /** Translate a key with `{name}` placeholder substitution. */ export type Translate = (key: string, params?: Record) => string; /** How the heatmap aggregates each cell. */ export type HeatMode = 'daily' | 'weekly' | 'cumulative'; /** The heatmap modes, in the order the switch shows them. */ export declare const HEAT_MODES: readonly HeatMode[]; /** Props the `settings.section` registration injects. */ export interface UsageSectionProps { /** Translator bound to this plugin's locale namespace. */ t?: Translate; /** * Reads the active DSH locale id, re-read on every render. * * The numbers follow the UI language rather than the browser's, so a user who * switched DSH to Chinese in Settings reads `3.7亿` instead of `370M`. It is a * reader rather than a value because the shell re-renders this entry on every * locale revision while the inject face itself is materialized only once per * registration. * @returns A BCP-47 tag, or `undefined` when no locale seat is installed. */ readLocale?: () => string | undefined; } /** Build a translator from a dictionary, falling back to a second one. */ export declare function makeTranslate(dict: Record, fallback: Record): Translate; /** One cell of the heatmap. */ export interface HeatCell { /** Stable key: the day this cell represents. */ key: string; /** The day the cell is anchored on. */ date: string; /** The value the cell encodes under the active mode. */ value: number; /** Ramp step, `0`-`4`. */ level: number; /** * Whether this cell only pads a block out to the shared column count. * * A year is 52 or 53 weeks, which is odd, so halving it leaves one block with * a column more than the other. Both blocks draw onto the same grid width, so * that difference would give them visibly different cell sizes. The short * block is padded to match instead, and the padding is hidden. */ trailing?: boolean; /** * Whether this cell lies after the window's last day. * * The grid is padded forward to the end of the current week so every column * holds seven days. Those positions are days that have not happened: they * keep their place and their empty colour, but they claim nothing — no date * in the accessibility tree, no tooltip, no hover readout. */ future?: boolean; } /** One stacked heatmap block: six months of columns plus its own month axis. */ export interface HeatBlock { /** Cells in column-major fill order. */ cells: HeatCell[]; /** One entry per column, labelled only under the month it begins. */ months: Array<{ key: string; label: string; }>; } /** The heatmap's built grid. */ export interface HeatGrid { /** The stacked blocks, earliest first. */ blocks: HeatBlock[]; /** * Columns in one block — the count EVERY block draws, padding included. * * Both the CSS grid (`repeat(N, 1fr)`) and the width formula that decides how * large a cell may grow are built from this one number, so the cells and the * month axis can never disagree about where column `i` starts. */ columnsPerBlock: number; /** Columns across one block before padding: half the year, rounded up. */ realColumnsPerBlock: number; /** Total columns in the year, as built (52 or 53 for a year, before trimming). */ columnCount: number; /** Whether any day INSIDE the window recorded tokens. */ hasActivity: boolean; } /** How many stacked blocks a year is split into. Two blocks of six months. */ export declare const HEAT_BLOCKS = 2; /** * Id shared by the `Token activity` heading and the grids it labels. * * A grid needs an accessible name, and the heading sitting immediately above it * already is that name — so the two are tied together rather than duplicating * the string into an `aria-label`. */ export declare const HEAT_TITLE_ID = "tdd-heat-title"; /** * Build the heatmap as stacked six-month blocks. * * Both ends are padded to whole weeks: the first column back to its Sunday and * the last forward to its Saturday. The grid fills column-major over exactly * seven rows, so an unpadded end would leave a short final column — harmless in * CSS, but it makes the grid's shape depend on which weekday "today" happens to * be. Cumulative padding carries the final total forward so the series stays * monotonic. * * The split is by COLUMN, not by calendar month. Twelve months is 52 or 53 * weeks, which does not divide in half evenly; splitting on a month boundary * would put 27 columns in one block and 26 in the other, and because the * columns are fluid that would give the two blocks visibly different cell * sizes. Halving the week count keeps them even, and the one column a year of * odd length leaves over is padded away so both blocks draw the same size cell. * @param snapshot - The snapshot carrying the day buckets and window. * @param mode - How each cell aggregates. * @param locale - Locale for the month names. * @returns The stacked blocks, the per-block column count and the year's total. */ export declare function buildHeatmap(snapshot: UsageSnapshot, mode: HeatMode, locale?: string): HeatGrid; /** * What a heatmap cell is ABOUT, as a date. * * In weekly mode a cell carries its whole column's total, so it stands for the * week and is named by the week's first day rather than by itself. Exported * because the panel's mode is internal state: a static render is always daily, * so the weekly wording can only be asserted directly. * @param cell - The cell. * @param mode - Active aggregation mode. * @param t - Translator. * @param locale - Locale for the date. * @returns The anchor label, for example `7 May 2026` or `week of 3 May 2026`. */ export declare function heatCellAnchor(cell: HeatCell, mode: HeatMode, t: Translate, locale?: string): string; /** * The `date · value` readout shared by a cell's tooltip and the hover line. * @param cell - The cell. * @param mode - Active aggregation mode. * @param t - Translator. * @param locale - Locale for the date and the count. * @returns The readout text, for example `7 May 2026 · 1,234 tokens`. */ export declare function heatCellDescription(cell: HeatCell, mode: HeatMode, t: Translate, locale?: string): string; /** * Props for {@link UsageView}, the pure presentation component. */ export interface UsageViewProps { /** Translator bound to this plugin's locale namespace. */ t: Translate; /** Locale used for number and date formatting. */ locale?: string; /** The snapshot to render; `undefined` while the first read is in flight. */ snapshot?: UsageSnapshot; /** Whether a read is in flight. */ loading: boolean; /** Failure text from the last read, when it failed. */ error?: string; /** Whether the failure is a Host half older than this browser half. */ staleHost?: boolean; /** Called when the user asks for a fresh read. */ onRefresh: () => void; } /** * Render the usage page from an already-computed snapshot. * * Split from {@link UsageSection} on purpose: everything Codex-shaped lives * here and takes its data as a prop, so the layout can be rendered and asserted * without a Host, a network, or a browser. * @param props - Snapshot plus the refresh callback. * @returns The panel element. */ export declare function UsageView(props: UsageViewProps): ReactNode; /** Props for {@link UsageSection}. */ export interface UsageSectionOptions extends UsageSectionProps { /** Dictionary resolved for the active language. */ dictionary?: Record; /** Fallback dictionary, normally English. */ fallbackDictionary?: Record; } /** * The settings page: fetch a snapshot, then hand it to {@link UsageView}. * @param props - Injected translator and dictionaries. * @returns The panel element. */ export declare function UsageSection(props: UsageSectionOptions): ReactNode;