uicore-ts
Version:
UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha
93 lines (92 loc) • 4.03 kB
TypeScript
import { UIObject } from "./UIObject";
export interface UIColorDescriptor {
red: number;
green: number;
blue: number;
alpha?: number;
}
export type UIColorSemanticKey = string;
export declare class UIColor extends UIObject {
static _liveColors: WeakRef<UIColor>[];
static _registrationMap: Map<string, UIColor>;
static _cssSubscriptions: Map<string, Set<() => void>>;
stringValue: string;
semanticKey?: UIColorSemanticKey;
_semanticClass?: typeof UIColor;
_elementRef?: HTMLElement;
_styleProperty?: string;
constructor(stringValue: string, semanticKey?: UIColorSemanticKey);
toString(): string;
/**
* Re-resolves this instance's stringValue from its class's static getter
* matching the semanticKey, then writes the new value directly to the DOM
* via the stored element reference and style property.
* No-op if this instance has no semanticKey.
*/
apply(): void;
/**
* Assigns a semantic key and the class that owns it to this color instance.
* Intended for derived colors that should participate in theme switching,
* e.g. `BSColor._primaryBase.colorWithAlpha(0.5).withSemanticKey("primaryShadow", BSColor)`.
* Returns `this` for fluent chaining.
*/
withSemanticKey(semanticKey: UIColorSemanticKey, semanticClass: typeof UIColor): this;
/**
* Iterates all live registered UIColor instances, calls apply() on each,
* compacts dead WeakRefs in the same pass, then fires any CSS subscriptions
* whose semantic key was affected.
*/
static applySemanticColors(): void;
/**
* Updates the backing field for a semantic color and re-applies all live
* semantic colors. The backing field is always `_` + semanticKey, e.g.
* `BSColor.updateSemanticColor("primary", "#ff0000")` sets `BSColor._primary`.
* Called as a static method on the subclass that owns the color.
*/
static updateSemanticColor(semanticKey: UIColorSemanticKey, value: string): void;
/**
* Registers a callback to be fired when applySemanticColors() affects
* the given semantic key. Intended for injected CSS blocks that cannot
* be tracked via the colorStyleProxy.
*/
static subscribe(semanticKey: UIColorSemanticKey, callback: () => void): void;
static unsubscribe(semanticKey: UIColorSemanticKey, callback: () => void): void;
static get redColor(): UIColor;
static get blueColor(): UIColor;
static get greenColor(): UIColor;
static get yellowColor(): UIColor;
static get blackColor(): UIColor;
static get brownColor(): UIColor;
static get whiteColor(): UIColor;
static get greyColor(): UIColor;
static get lightGreyColor(): UIColor;
static get transparentColor(): UIColor;
static get clearColor(): UIColor;
static get undefinedColor(): UIColor;
static get nilColor(): UIColor;
static nameToHex(name: string): string | undefined;
static hexToDescriptor(c: string): UIColorDescriptor;
static rgbToDescriptor(colorString: string): {
red: number;
green: number;
blue: number;
alpha: number;
};
get colorDescriptor(): UIColorDescriptor;
colorWithRed(red: number): UIColor;
colorWithGreen(green: number): UIColor;
colorWithBlue(blue: number): UIColor;
colorWithAlpha(alpha: number): UIColor;
static colorWithRGBA(red: number, green: number, blue: number, alpha?: number): UIColor;
static colorWithDescriptor(descriptor: UIColorDescriptor): UIColor;
private static defaultAlphaToOne;
colorByMultiplyingRGB(multiplier: number): UIColor;
/**
* Returns the perceptual lightness (L*) of this color in the range [0, 1],
* using the CIELAB formula. 0 = absolute black, 1 = absolute white.
* Unlike raw relative luminance, this scale is perceptually uniform —
* 0.5 is the genuine visual midpoint between black and white.
*/
get perceivedLightness(): number;
get isLight(): boolean;
}