import type { SizableText } from '@hanzo/gui' import type { ComponentProps } from 'react' /** * How hard a string is set. * * Three values, measured across the Lux surfaces rather than chosen: the * ordinary weight for everything that is read, a half step up for the smallest * rung, where a face at the ordinary weight goes thin, and a firmer one for a * string that is pressed or names a value. There is no fourth above them. * * Weight is not keyed to size. The same 14px rung is set at the ordinary weight * where it is reading and at the firm one where it is a control, and the same is * true at 16, so the ladder in `tokens.css` can only ever set the default and a * string that wants emphasis says so where it stands. That is what these names * are for. * * The values are token references and not numbers, so a tenant retunes the whole * fleet by moving `--weight-*` and the appearance panel still reaches them. The * numbers themselves live in `tokens.css` beside the ramp they belong to. * * Write `size` before `fontWeight`, always. `size` is a variant, and the engine * expands it into a whole style block — size, leading, letterspacing and a weight * off its own ladder — at the position the prop sits in. A `fontWeight` written * above it is overwritten by that expansion and vanishes: no warning, no class in * the output, a line that compiles and does nothing. */ /** * What a weight may be. * * The text primitive's own type, narrowed to its string members. Both halves of * that matter: a Lux surface sets a weight through the primitive, and a plain * `style` object takes one too — a documentation page, an element outside the * engine — and `CSSProperties` accepts a string where the primitive's type also * admits numbers. The intersection is the one type both will take, so no call * site casts. */ type Weight = NonNullable['fontWeight']> & string /** * A token reference, as a weight. * * The prop's type enumerates the nine static cuts and `unset`. Zen is variable * across 100–900 and this ladder draws three weights that are not cuts, so the * values have to be custom properties — which the type has no room for and the * renderer passes through to `font-weight` untouched. The correction is stated * once, here, rather than at each of the sixty-odd places a Lux surface marks a * string. */ const token = (name: string): Weight => `var(${ name })` as unknown as Weight export const weight = { /** Running text: what the page is set in, and what a heading takes too. */ plain: token('--weight-normal'), /** The smallest rung, which needs the half step to hold its colour. */ label: token('--weight-medium'), /** A string that is pressed or names a value — a control, a tab, a title. */ mark: token('--weight-semibold'), } as const /** * A weight, as a prop takes it. * * Exported so a component that lets a caller choose one can say so in its own * signature without repeating the cast. */ export type { Weight }