UNPKG

@llselect/core

Version:

Low-level select: a minimal, flexible, framework-agnostic replacement for the native HTML select element.

51 lines • 3.42 kB
/** * The `colorScheme` setting's values. * - `'auto'`, the default: the library decides from the root element's computed CSS. The setting's * docstring on {@link LLSelectBaseSettings.colorScheme} explains the order. * - `'light'` or `'dark'`: the select component shows that scheme. The CSS sources and the operating system do not matter. The bootstrap-5 theme still takes its colors from Bootstrap's own CSS variables; see the README section "Dark color scheme". * @group Settings * @category Base */ export type LLSelectColorScheme = 'auto' | 'light' | 'dark'; /** The attribute the resolver writes on the root element. The themes key their dark values on it. */ export declare const COLOR_SCHEME_ATTRIBUTE = "data-llselect-color-scheme"; /** The CSS variable a host page or a built-in mark sets on any ancestor: `light`, `dark` or `auto`. */ export declare const COLOR_SCHEME_VARIABLE = "--llselect-color-scheme"; /** The four inputs of one decision, as read from the page. */ export interface ColorSchemeInputs { setting: LLSelectColorScheme; /** The computed `--llselect-color-scheme` of the root element; empty when nobody set it. */ variable: string; /** The computed CSS property `color-scheme` of the root element; empty where the browser lacks the property. */ declared: string; osPrefersDark: boolean; } /** * The decision, as a pure function of its inputs (DESIGN.md "How the resolver decides"). * Order: the forced setting; the variable (`auto` = the OS preference); the * declared `color-scheme` combined with the OS preference; otherwise light. */ export declare function resolveColorScheme(inputs: ColorSchemeInputs): 'light' | 'dark'; /** Reads the inputs for a root element: one getComputedStyle call when the setting is `'auto'`. */ export declare function readColorSchemeInputs(rootEl: HTMLElement, setting: LLSelectColorScheme): ColorSchemeInputs; /** One select component's decision in two steps: `read` resolves the scheme from the page, `apply` writes the attribute. */ export interface ColorSchemeDecision { read(): void; apply(): void; } /** The value a new `'auto'` select component writes before its first decision: the document's last `'auto'` decision on a connected root, or light. */ export declare function provisionalColorScheme(doc: Document): 'light' | 'dark'; /** Records an `'auto'` decision made on a connected root as the document's latest, the next select component's provisional value. */ export declare function rememberColorScheme(doc: Document, scheme: 'light' | 'dark'): void; export declare function queueFirstDecision(rootEl: HTMLElement, decision: ColorSchemeDecision): void; /** Drops the pending decision only when it is still this one (a newer instance may own the element now). */ export declare function cancelFirstDecision(rootEl: HTMLElement, decision: ColorSchemeDecision): void; /** * Called by every constructor: the new instance owns the element from now on. * An older instance on the same element loses its pending decision and its * subscription, so it can neither overwrite the attribute nor keep deciding. */ export declare function claimColorSchemeRoot(rootEl: HTMLElement): void; export declare function subscribeColorScheme(rootEl: HTMLElement, subscriber: ColorSchemeDecision): void; export declare function unsubscribeColorScheme(rootEl: HTMLElement): void; //# sourceMappingURL=color-scheme.d.ts.map