/** * @file * * Mock of Obsidian's `ColorComponent`, a color picker control. */ import type { ColorComponent as ColorComponentOriginal, HSL as HSLOriginal, RGB as RGBOriginal } from 'obsidian'; import { ValueComponent } from './ValueComponent.cjs'; /** * Mock of Obsidian's `ColorComponent`. * * As in Obsidian, the value lives in {@link ColorComponent.colorPickerEl}, a real ``, so it reads * as a lowercase six-digit hex string such as `#ff8800` and starts as `#000000`. The RGB and HSL accessors convert * to and from that string with Obsidian's own formulas: HSL uses an integer hue from 0 to 360 and integer saturation * and lightness from 0 to 100. */ export declare class ColorComponent extends ValueComponent { /** * The callback registered with {@link ColorComponent.onChange}, if any. */ changeCallback?: (value: string) => unknown; /** * The `` element the component renders. */ colorPickerEl: HTMLInputElement; /** * Creates a color picker inside a container. Its `change` event calls the change callback, as in Obsidian. * * @param containerEl - The element the color input is appended to. */ constructor(containerEl: HTMLElement); /** * Mock-only factory: creates a color picker, spyable via `vi.spyOn(ColorComponent, 'create__')`. * * @param containerEl - The element the color input is appended to. * @returns The new color picker. */ static create__(containerEl: HTMLElement): ColorComponent; /** * Mock-only: views a value typed as Obsidian's `ColorComponent` as this mock. The numbered subclass variant of * `fromOriginalType__`. * * @param value - The value typed as the original `ColorComponent`. * @returns The same object, typed as the mock. */ static fromOriginalType3__(value: ColorComponentOriginal): ColorComponent; /** * Mock-only: views this mock as Obsidian's `ColorComponent` type. The numbered subclass variant of * `asOriginalType__`. * * @returns The same object, typed as the original `ColorComponent`. */ asOriginalType3__(): ColorComponentOriginal; /** * Mock-only construction hook, called at the end of the constructor; a no-op meant for * `vi.spyOn(ColorComponent.prototype, 'constructor3__')`. * * @param _containerEl - The container the color picker was created in. */ constructor3__(_containerEl: HTMLElement): void; /** * Gets the current color. * * @returns The color input's value, a lowercase hex string; `#000000` until a color is set. */ getValue(): string; /** * Gets the current color as HSL. * * @returns The color's integer hue (0-360), saturation (0-100) and lightness (0-100). */ getValueHsl(): HSLOriginal; /** * Gets the current color as RGB. * * @returns The red, green and blue channels, each 0-255; black when the value is not a hex color. */ getValueRgb(): RGBOriginal; /** * Sets the handler run when the color changes, replacing any previous one. * * @param callback - Receives the new hex value. * @returns This component, for chaining. */ onChange(callback: (value: string) => unknown): this; /** * Disables or enables the color picker and its input. * * @param disabled - Whether the color picker is disabled. * @returns This component, for chaining. */ setDisabled(disabled: boolean): this; /** * Sets the current color. When it differs from the input's value, it is written to the input and the change * handler is called with the value the input then holds; an unchanged value does nothing. * * @param value - The color as a hex string such as `#ff8800`. * @returns This component, for chaining. */ setValue(value: string): this; /** * Sets the current color from HSL, converting it to RGB and on through {@link ColorComponent.setValueRgb}. * * @param hsl - The color, with hue 0-360 and saturation and lightness 0-100. * @returns This component, for chaining. */ setValueHsl(hsl: HSLOriginal): this; /** * Sets the current color from RGB, converting it to a hex string through {@link ColorComponent.setValue}. * * @param rgb - The color, with each channel an integer 0-255. * @returns This component, for chaining. */ setValueRgb(rgb: RGBOriginal): this; }