@mkbabb/value.js 0.5.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -56
- package/dist/easing.d.ts +49 -0
- package/dist/index.d.ts +19 -8
- package/dist/math.d.ts +1 -1
- package/dist/parsing/animation-shorthand.d.ts +19 -0
- package/dist/parsing/color.d.ts +10 -3
- package/dist/parsing/extract.d.ts +48 -0
- package/dist/parsing/index.d.ts +5 -20
- package/dist/parsing/serialize.d.ts +24 -0
- package/dist/parsing/stylesheet.d.ts +44 -0
- package/dist/parsing/units.d.ts +24 -6
- package/dist/parsing/utils.d.ts +5 -0
- package/dist/postcss-CRluLK2m.js +6400 -0
- package/dist/quantize/cluster.d.ts +45 -0
- package/dist/quantize/index.d.ts +14 -0
- package/dist/quantize/types.d.ts +39 -0
- package/dist/standalone-Ck3UyY5I.js +3458 -0
- package/dist/units/color/constants.d.ts +21 -0
- package/dist/units/color/contrast.d.ts +35 -0
- package/dist/units/color/conversions/cylindrical.d.ts +13 -0
- package/dist/units/color/conversions/direct.d.ts +41 -0
- package/dist/units/color/conversions/hex.d.ts +3 -0
- package/dist/units/color/conversions/index.d.ts +17 -0
- package/dist/units/color/conversions/kelvin.d.ts +5 -0
- package/dist/units/color/conversions/lab.d.ts +8 -0
- package/dist/units/color/conversions/oklab.d.ts +11 -0
- package/dist/units/color/conversions/transfer.d.ts +22 -0
- package/dist/units/color/conversions/xyz-extended.d.ts +13 -0
- package/dist/units/color/dispatch.d.ts +26 -0
- package/dist/units/color/gamut.d.ts +6 -0
- package/dist/units/color/index.d.ts +220 -116
- package/dist/units/color/mix.d.ts +16 -0
- package/dist/units/color/normalize.d.ts +3 -3
- package/dist/units/index.d.ts +39 -1
- package/dist/units/interpolate.d.ts +47 -0
- package/dist/units/normalize.d.ts +47 -7
- package/dist/units/utils.d.ts +1 -1
- package/dist/utils.d.ts +3 -2
- package/dist/value.js +4229 -5229
- package/package.json +62 -30
- package/scripts/migrate-keyframes-js-lerp.mjs +257 -0
- package/dist/units/color/utils.d.ts +0 -77
- package/dist/value.cjs +0 -20
|
@@ -764,6 +764,27 @@ export declare const COLOR_SPACE_DENORM_UNITS: {
|
|
|
764
764
|
};
|
|
765
765
|
};
|
|
766
766
|
export type ColorSpace = keyof typeof COLOR_SPACE_RANGES;
|
|
767
|
+
export type ColorSpaceRanges = typeof COLOR_SPACE_RANGES;
|
|
768
|
+
export type ColorSpaceDenormUnits = typeof COLOR_SPACE_DENORM_UNITS;
|
|
769
|
+
/** Components of a color space (the keys of its range record). */
|
|
770
|
+
export type ColorComponent<C extends ColorSpace> = keyof ColorSpaceRanges[C];
|
|
771
|
+
/** A `{ min, max }` bound — the value type of every per-unit range entry. */
|
|
772
|
+
export interface ColorSpaceBound {
|
|
773
|
+
readonly min: number;
|
|
774
|
+
readonly max: number;
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Typed bound lookup for `(space, component)` at a given unit, with the CSS
|
|
778
|
+
* `number` fallback. Replaces the former untyped `COLOR_SPACE_RANGES` index
|
|
779
|
+
* + `ranges[unit] ?? ranges.number` idiom — returns a precise `ColorSpaceBound`
|
|
780
|
+
* so the `{ min, max }` destructure at every call site is fully typed.
|
|
781
|
+
*/
|
|
782
|
+
export declare const getColorSpaceBound: (colorSpace: ColorSpace, component: string, unit: string) => ColorSpaceBound;
|
|
783
|
+
/**
|
|
784
|
+
* Typed denorm-unit lookup for `(space, component)`. Replaces the former
|
|
785
|
+
* untyped `COLOR_SPACE_DENORM_UNITS` index — returns a precise `string`.
|
|
786
|
+
*/
|
|
787
|
+
export declare const getColorSpaceDenormUnit: (colorSpace: ColorSpace, component: string) => string;
|
|
767
788
|
export declare const COLOR_SPACE_NAMES: {
|
|
768
789
|
readonly rgb: "RGB";
|
|
769
790
|
readonly hsl: "HSL";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { OKLCHColor, Color } from '.';
|
|
2
|
+
/**
|
|
3
|
+
* Compute a contrast-safe OKLCH tuple by shifting lightness away from
|
|
4
|
+
* the background when the original color is too close.
|
|
5
|
+
*
|
|
6
|
+
* Preserves hue; reduces chroma at extreme lightness to stay in gamut.
|
|
7
|
+
*
|
|
8
|
+
* @param L OKLab/OKLCH lightness [0, 1]
|
|
9
|
+
* @param C OKLCH chroma (normalized [0, 1], physical max ~0.5)
|
|
10
|
+
* @param H OKLCH hue in degrees [0, 360]
|
|
11
|
+
* @param bgLightness background surface lightness in OKLab [0, 1]
|
|
12
|
+
* @param minContrast minimum lightness distance (default 0.35)
|
|
13
|
+
* @returns adjusted { L, C, H } tuple
|
|
14
|
+
*/
|
|
15
|
+
export declare function computeSafeAccent(L: number, C: number, H: number, bgLightness: number, minContrast?: number): {
|
|
16
|
+
L: number;
|
|
17
|
+
C: number;
|
|
18
|
+
H: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Extract OKLCH lightness from any Color by converting through OKLab.
|
|
22
|
+
*/
|
|
23
|
+
export declare function getOklchLightness(color: Color): number;
|
|
24
|
+
/**
|
|
25
|
+
* Check if a color needs contrast adjustment against a background.
|
|
26
|
+
*/
|
|
27
|
+
export declare function needsContrastAdjustment(color: Color, bgLightness: number, minContrast?: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Convert any Color to a contrast-safe OKLCHColor for use as foreground
|
|
30
|
+
* text/icons against a background of the given lightness.
|
|
31
|
+
*
|
|
32
|
+
* If the color already has sufficient contrast, returns an OKLCH clone
|
|
33
|
+
* of the original (no adjustment).
|
|
34
|
+
*/
|
|
35
|
+
export declare function safeAccentColor(color: Color, bgLightness: number, minContrast?: number): OKLCHColor;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { HSLColor, HSVColor, HWBColor, RGBColor, XYZColor } from '..';
|
|
2
|
+
export declare const hsv2hsl: ({ h, s, v, alpha }: HSVColor) => HSLColor;
|
|
3
|
+
export declare const hsl2hsv: ({ h, s, l, alpha }: HSLColor) => HSVColor;
|
|
4
|
+
export declare const hwb2hsl: ({ h, w, b, alpha }: HWBColor) => HSLColor;
|
|
5
|
+
export declare const hsl2hwb: ({ h, s, l, alpha }: HSLColor) => HWBColor;
|
|
6
|
+
export declare const rgb2hsl: ({ r, g, b, alpha }: RGBColor) => HSLColor;
|
|
7
|
+
export declare function hsl2rgb({ h, s, l, alpha }: HSLColor): RGBColor;
|
|
8
|
+
export declare function hsl2xyz(hsl: HSLColor): XYZColor<number>;
|
|
9
|
+
export declare function xyz2hsl(xyz: XYZColor): HSLColor<number>;
|
|
10
|
+
export declare function hsv2xyz(hsv: HSVColor): XYZColor;
|
|
11
|
+
export declare function xyz2hsv(xyz: XYZColor): HSVColor;
|
|
12
|
+
export declare function hwb2xyz(hwb: HWBColor): XYZColor;
|
|
13
|
+
export declare function xyz2hwb(xyz: XYZColor): HWBColor;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { OKLABColor, OKLCHColor, RGBColor, Color, ColorSpaceMap, HSLColor } from '..';
|
|
2
|
+
import { ColorSpace } from '../constants';
|
|
3
|
+
/** Direct OKLab → RGB. Skips XYZColor allocation + one matrix multiply. */
|
|
4
|
+
export declare function directOklabToRgb(oklab: OKLABColor): RGBColor;
|
|
5
|
+
/** Direct RGB → OKLab. Skips XYZColor allocation + one matrix multiply. */
|
|
6
|
+
export declare function directRgbToOklab(rgb: RGBColor): OKLABColor;
|
|
7
|
+
/** Direct OKLCH → RGB. Polar → Cartesian → direct OKLab→RGB. */
|
|
8
|
+
export declare function directOklchToRgb(oklch: OKLCHColor): RGBColor;
|
|
9
|
+
/** Direct RGB → OKLCH. Direct RGB→OKLab Cartesian → polar (skip OKLABColor wrap). */
|
|
10
|
+
export declare function directRgbToOklch(rgb: RGBColor): OKLCHColor;
|
|
11
|
+
/** Direct HSL → RGB. Already a closed-form cylindrical conversion (no XYZ). */
|
|
12
|
+
export declare function directHslToRgb(hsl: HSLColor): RGBColor;
|
|
13
|
+
/** Direct RGB → HSL. Already a closed-form cylindrical conversion (no XYZ). */
|
|
14
|
+
export declare function directRgbToHsl(rgb: RGBColor): HSLColor;
|
|
15
|
+
/**
|
|
16
|
+
* A `From → To` direct conversion. The direct-path functions operate on
|
|
17
|
+
* numeric channels and build same-arity `number`-component colors, so the
|
|
18
|
+
* component type is concrete `number`.
|
|
19
|
+
*/
|
|
20
|
+
type DirectPath<From extends ColorSpace, To extends ColorSpace> = (color: ColorSpaceMap<number>[From]) => ColorSpaceMap<number>[To];
|
|
21
|
+
/**
|
|
22
|
+
* Distributes over every `${From}->${To}` color-space pair; each entry is the
|
|
23
|
+
* exact `From → To` conversion signature (or absent).
|
|
24
|
+
*/
|
|
25
|
+
export type DirectPathsTable = {
|
|
26
|
+
[K in `${ColorSpace}->${ColorSpace}`]?: K extends `${infer From extends ColorSpace}->${infer To extends ColorSpace}` ? DirectPath<From, To> : never;
|
|
27
|
+
};
|
|
28
|
+
export declare const DIRECT_PATHS: DirectPathsTable;
|
|
29
|
+
/**
|
|
30
|
+
* Typed `DIRECT_PATHS` lookup. Returns the wired direct conversion for
|
|
31
|
+
* `from → to` (or `undefined` when the pair routes through the XYZ hub). The
|
|
32
|
+
* return type is narrowed to the target space `C` so `color2` consumes it
|
|
33
|
+
* cast-free.
|
|
34
|
+
*
|
|
35
|
+
* The `directKey` is composed from runtime values, so TS cannot pick a single
|
|
36
|
+
* `DirectPathsTable` entry statically — the lone `as` re-asserts the table
|
|
37
|
+
* value as the `C`-targeted signature. This is a narrowing assertion, not a
|
|
38
|
+
* type-erasing double cast.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getDirectPath: <C extends ColorSpace>(from: ColorSpace, to: C) => ((color: Color<number>) => ColorSpaceMap<number>[C]) | undefined;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Conversion-module aggregate barrel.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports every `{from}2{to}` conversion function from the 6 focused
|
|
5
|
+
* conversion modules. Consumers that need a single conversion import the
|
|
6
|
+
* specific module directly; this barrel exists for namespace-style access
|
|
7
|
+
* (`import * as Conversions`) where the `{from}2{to}` name is computed.
|
|
8
|
+
*
|
|
9
|
+
* G.W1 Lane B — created with the `src/units/color/utils.ts` G3 decomposition.
|
|
10
|
+
*/
|
|
11
|
+
export { hex2rgb, rgb2hex } from './hex';
|
|
12
|
+
export { kelvin2rgb, rgb2kelvin, kelvin2xyz, xyz2kelvin } from './kelvin';
|
|
13
|
+
export { hsv2hsl, hsl2hsv, hwb2hsl, hsl2hwb, rgb2hsl, hsl2rgb, hsl2xyz, xyz2hsl, hsv2xyz, xyz2hsv, hwb2xyz, xyz2hwb, } from './cylindrical';
|
|
14
|
+
export { xyz2lab, lab2xyz, lch2lab, lab2lch, lch2xyz, xyz2lch, } from './lab';
|
|
15
|
+
export { oklab2xyz, xyz2oklab, oklab2lab, lab2oklab, oklab2oklch, oklch2oklab, oklch2lab, lab2oklch, oklch2xyz, xyz2oklch, } from './oklab';
|
|
16
|
+
export { srgbToLinear, linearToSrgb, adobeRgbToLinear, linearToAdobeRgb, proPhotoToLinear, linearToProPhoto, rec2020ToLinear, linearToRec2020, } from './transfer';
|
|
17
|
+
export { rgb2xyz, xyz2rgb, linearSrgb2xyz, xyz2linearSrgb, displayP32xyz, xyz2displayP3, adobeRgb2xyz, xyz2adobeRgb, proPhoto2xyz, xyz2proPhoto, rec20202xyz, xyz2rec2020, } from './xyz-extended';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { KelvinColor, RGBColor, XYZColor } from '..';
|
|
2
|
+
export declare const kelvin2rgb: ({ kelvin, alpha }: KelvinColor) => RGBColor;
|
|
3
|
+
export declare const rgb2kelvin: ({ r, g, b, alpha }: RGBColor) => KelvinColor;
|
|
4
|
+
export declare function kelvin2xyz(kelvin: KelvinColor): XYZColor;
|
|
5
|
+
export declare function xyz2kelvin(xyz: XYZColor): KelvinColor;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LABColor, LCHColor, XYZColor } from '..';
|
|
2
|
+
import { WhitePoint } from '../constants';
|
|
3
|
+
export declare function xyz2lab(xyz: XYZColor, toWhitePoint?: WhitePoint): LABColor;
|
|
4
|
+
export declare function lab2xyz(lab: LABColor): XYZColor;
|
|
5
|
+
export declare function lch2lab({ l, c, h, alpha }: LCHColor): LABColor;
|
|
6
|
+
export declare function lab2lch({ l, a, b, alpha }: LABColor): LCHColor;
|
|
7
|
+
export declare function lch2xyz(lch: LCHColor): XYZColor;
|
|
8
|
+
export declare function xyz2lch(xyz: XYZColor): LCHColor;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LABColor, OKLABColor, OKLCHColor, XYZColor } from '..';
|
|
2
|
+
export declare function oklab2xyz({ l, a, b, alpha }: OKLABColor): XYZColor;
|
|
3
|
+
export declare function xyz2oklab(xyz: XYZColor): OKLABColor;
|
|
4
|
+
export declare function oklab2lab(oklab: OKLABColor): LABColor;
|
|
5
|
+
export declare function lab2oklab(lab: LABColor): OKLABColor;
|
|
6
|
+
export declare function oklab2oklch({ l, a, b, alpha }: OKLABColor): OKLCHColor;
|
|
7
|
+
export declare function oklch2oklab({ l, c, h, alpha }: OKLCHColor): OKLABColor;
|
|
8
|
+
export declare function oklch2lab(oklch: OKLCHColor): LABColor;
|
|
9
|
+
export declare function lab2oklch(lab: LABColor): OKLCHColor;
|
|
10
|
+
export declare function oklch2xyz(oklch: OKLCHColor): XYZColor;
|
|
11
|
+
export declare function xyz2oklch(xyz: XYZColor): OKLCHColor;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transfer functions — gamma encode/decode for the RGB-family color spaces.
|
|
3
|
+
*
|
|
4
|
+
* Each wide-gamut RGB space carries its own opto-electronic transfer function
|
|
5
|
+
* (OETF) and its inverse. These are pure scalar functions — no color-class
|
|
6
|
+
* dependency — consumed by `xyz-extended.ts` (the matrix-multiply converters)
|
|
7
|
+
* and by the OKLab/RGB direct paths in `dispatch.ts`.
|
|
8
|
+
*
|
|
9
|
+
* G.W1 Lane B — extracted from `src/units/color/utils.ts` (G3 decomposition).
|
|
10
|
+
*/
|
|
11
|
+
/** Convert an sRGB channel to linear-light sRGB. */
|
|
12
|
+
export declare function srgbToLinear(channel: number): number;
|
|
13
|
+
/** Convert a linear-light sRGB channel back to gamma-encoded sRGB. */
|
|
14
|
+
export declare function linearToSrgb(channel: number): number;
|
|
15
|
+
/** Identity transfer (linear-light spaces — no gamma curve). */
|
|
16
|
+
export declare const linearTransfer: (c: number) => number;
|
|
17
|
+
export declare function adobeRgbToLinear(c: number): number;
|
|
18
|
+
export declare function linearToAdobeRgb(c: number): number;
|
|
19
|
+
export declare function proPhotoToLinear(c: number): number;
|
|
20
|
+
export declare function linearToProPhoto(c: number): number;
|
|
21
|
+
export declare function rec2020ToLinear(c: number): number;
|
|
22
|
+
export declare function linearToRec2020(c: number): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AdobeRGBColor, DisplayP3Color, LinearSRGBColor, ProPhotoRGBColor, Rec2020Color, RGBColor, XYZColor } from '..';
|
|
2
|
+
export declare function rgb2xyz({ r, g, b, alpha }: RGBColor): XYZColor;
|
|
3
|
+
export declare const xyz2rgb: ({ x, y, z, alpha }: XYZColor, correctGamut?: boolean) => RGBColor;
|
|
4
|
+
export declare function linearSrgb2xyz(color: LinearSRGBColor): XYZColor;
|
|
5
|
+
export declare function xyz2linearSrgb(xyz: XYZColor): LinearSRGBColor;
|
|
6
|
+
export declare function displayP32xyz(color: DisplayP3Color): XYZColor;
|
|
7
|
+
export declare function xyz2displayP3(xyz: XYZColor): DisplayP3Color;
|
|
8
|
+
export declare function adobeRgb2xyz(color: AdobeRGBColor): XYZColor;
|
|
9
|
+
export declare function xyz2adobeRgb(xyz: XYZColor): AdobeRGBColor;
|
|
10
|
+
export declare function proPhoto2xyz({ r, g, b, alpha }: ProPhotoRGBColor): XYZColor;
|
|
11
|
+
export declare function xyz2proPhoto({ x, y, z, alpha }: XYZColor): ProPhotoRGBColor;
|
|
12
|
+
export declare function rec20202xyz(color: Rec2020Color): XYZColor;
|
|
13
|
+
export declare function xyz2rec2020(xyz: XYZColor): Rec2020Color;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Color, ColorSpaceMap } from '.';
|
|
2
|
+
import { ColorSpace } from './constants';
|
|
3
|
+
import { hex2rgb, rgb2hex } from './conversions/hex';
|
|
4
|
+
export { hex2rgb, rgb2hex };
|
|
5
|
+
export { deltaEOK, isInSRGBGamut, DELTA_E_OK_JND } from './gamut';
|
|
6
|
+
export { computeSafeAccent, safeAccentColor, needsContrastAdjustment, getOklchLightness, } from './contrast';
|
|
7
|
+
export declare const getFormattedColorSpaceRange: <T extends ColorSpace>(colorSpace: T) => ColorSpaceMap<{
|
|
8
|
+
min: string;
|
|
9
|
+
max: string;
|
|
10
|
+
}>[T];
|
|
11
|
+
export declare function color2<T, C extends ColorSpace>(color: Color<T>, to: C): Color<T>;
|
|
12
|
+
export declare function gamutMap<C extends Color>(color: C): C;
|
|
13
|
+
export type HueInterpolationMethod = "shorter" | "longer" | "increasing" | "decreasing";
|
|
14
|
+
export declare const CYLINDRICAL_HUE_COMPONENT: Partial<Record<ColorSpace, string>>;
|
|
15
|
+
/**
|
|
16
|
+
* Interpolate between two hue values using the given method.
|
|
17
|
+
* Hues are in [0, 1] (normalized). Returns an interpolated hue in [0, 1].
|
|
18
|
+
* Handles NaN (CSS `none`): if one hue is NaN, the other's value is used.
|
|
19
|
+
*/
|
|
20
|
+
export declare function interpolateHue(h1: number, h2: number, t: number, method?: HueInterpolationMethod): number;
|
|
21
|
+
/**
|
|
22
|
+
* Mix two colors per CSS color-mix() specification.
|
|
23
|
+
* Both colors should be normalized (components in [0, 1]).
|
|
24
|
+
* Percentages p1, p2 are in [0, 1] (e.g. 0.5 = 50%).
|
|
25
|
+
*/
|
|
26
|
+
export declare function mixColors(col1: Color, col2: Color, p1: number, p2: number, space?: ColorSpace, hueMethod?: HueInterpolationMethod): Color;
|
|
@@ -58,3 +58,9 @@ export declare function srgbToOKLab(r: number, g: number, b: number): [number, n
|
|
|
58
58
|
* Returns clamped sRGB [0,1]³.
|
|
59
59
|
*/
|
|
60
60
|
export declare function gamutMapSRGB(r: number, g: number, b: number): [number, number, number];
|
|
61
|
+
/** OKLab (L,a,b) → OKLCH (L,C,H) with H in degrees [0,360). */
|
|
62
|
+
export declare function rawOklabToOklch(L: number, a: number, b: number): [number, number, number];
|
|
63
|
+
/** OKLCH (L,C,H) → OKLab (L,a,b). H in degrees. */
|
|
64
|
+
export declare function rawOklchToOklab(L: number, C: number, H: number): [number, number, number];
|
|
65
|
+
/** OKLab → clamped sRGB [0,255]. */
|
|
66
|
+
export declare function oklabToRgb255(L: number, a: number, b: number): [number, number, number];
|
|
@@ -1,155 +1,258 @@
|
|
|
1
1
|
import { ColorSpace, WhitePoint } from './constants';
|
|
2
|
+
declare const __ColorChannel: unique symbol;
|
|
3
|
+
export type ColorChannel<T = number> = T & {
|
|
4
|
+
readonly [__ColorChannel]: true;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Brand-erasing identity helper. Casts a plain `T` value to `ColorChannel<T>`
|
|
8
|
+
* at write sites that compute channels from arithmetic / interpolation. The
|
|
9
|
+
* `ColorChannel<T>` brand on declared fields requires an explicit cast on
|
|
10
|
+
* assignment — this helper makes the intent clear and keeps the line short.
|
|
11
|
+
*
|
|
12
|
+
* Zero runtime cost (identity function; inlined by V8).
|
|
13
|
+
*
|
|
14
|
+
* E.W1 Lane E — lifted from per-file duplicates in `utils.ts` + `contrast.ts`
|
|
15
|
+
* to live alongside the `ColorChannel<T>` brand declaration. Internal-only:
|
|
16
|
+
* NOT re-exported from `src/index.ts`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ch: <T>(v: T) => ColorChannel<T>;
|
|
19
|
+
/**
|
|
20
|
+
* Typed channel read. `key` is any channel name from `color.channels` /
|
|
21
|
+
* `color.keys()`; the result is the branded `ColorChannel<T>` slot value.
|
|
22
|
+
*
|
|
23
|
+
* The lone assertion re-narrows the index-signature read to `ColorChannel<T>` —
|
|
24
|
+
* a documented index-narrowing at the one dynamic-access boundary, not a
|
|
25
|
+
* type-erasing double cast.
|
|
26
|
+
*/
|
|
27
|
+
export declare const channelOf: <T>(color: Color<T>, key: string) => ColorChannel<T>;
|
|
28
|
+
/**
|
|
29
|
+
* Typed channel write. Accepts a `ColorChannel<T>` (use `ch()` to brand a raw
|
|
30
|
+
* computed value) and assigns it to the named slot.
|
|
31
|
+
*/
|
|
32
|
+
export declare const setChannel: <T>(color: Color<T>, key: string, value: ColorChannel<T>) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Abstract base class for all CSS color spaces.
|
|
35
|
+
*
|
|
36
|
+
* Generic over component type `T` — `number` for math operations,
|
|
37
|
+
* `ValueUnit` for CSS parsing/serialization.
|
|
38
|
+
*
|
|
39
|
+
* **L8 storage**: components live as own properties on the instance (e.g.
|
|
40
|
+
* `instance.r`, `instance.l`) — V8 hidden-class monomorphic. Subclasses declare
|
|
41
|
+
* their fields via `declare r: ColorChannel<T>` and override `get channels()`.
|
|
42
|
+
*
|
|
43
|
+
* All 15 color spaces extend this class. Conversion between spaces routes
|
|
44
|
+
* through XYZ D65 as the hub (see `utils.ts`). Components are normalized to
|
|
45
|
+
* [0,1] internally; physical ranges (e.g. [0,255] for RGB, [0,360] for hue)
|
|
46
|
+
* are applied on output.
|
|
47
|
+
*/
|
|
2
48
|
export declare abstract class Color<T = number> {
|
|
3
49
|
readonly colorSpace: ColorSpace;
|
|
4
50
|
alpha: T;
|
|
51
|
+
/**
|
|
52
|
+
* Dynamic channel index signature.
|
|
53
|
+
*
|
|
54
|
+
* **G.W2 Lane C (G-OPP-4) — BREAKING-decision verdict: KEEP (documented).**
|
|
55
|
+
*
|
|
56
|
+
* `Color<T>` is publicly barrel-exported (`src/index.ts`) and the demo
|
|
57
|
+
* dynamically indexes instances by a runtime `component: string`
|
|
58
|
+
* (`useColorModel.ts:197,206`, `ComponentSliders.vue:56,178`,
|
|
59
|
+
* `useSliderGradients.ts:36`). The signature is therefore part of the
|
|
60
|
+
* observable public surface — dropping it is a BREAKING change.
|
|
61
|
+
*
|
|
62
|
+
* It also *cannot* be tightened to a typed `[channel: string]:
|
|
63
|
+
* ColorChannel<T> | T` form: a TypeScript string index signature requires
|
|
64
|
+
* **every** declared member to be assignable to it, and `Color<T>` carries
|
|
65
|
+
* non-channel members (`whitePoint: WhitePoint`, `colorSpace: ColorSpace`,
|
|
66
|
+
* and the `toString`/`values`/`entries`/… methods) whose types are not
|
|
67
|
+
* assignable to a channel-value union. `any` is the only index type the
|
|
68
|
+
* heterogeneous class shape admits.
|
|
69
|
+
*
|
|
70
|
+
* The internal pipeline no longer *relies* on this `any` leak, though — the
|
|
71
|
+
* typed `ch<T>` channel accessors below (`channelOf` / `setChannel`) give
|
|
72
|
+
* `clone()`/`values()`/`entries()` + `interpolate.ts` + `normalize.ts`
|
|
73
|
+
* cast-free `ColorChannel<T>`-typed reads/writes. The index signature
|
|
74
|
+
* survives purely as the public dynamic-access affordance.
|
|
75
|
+
*/
|
|
5
76
|
[key: string]: any;
|
|
6
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Reference white point for this color instance.
|
|
79
|
+
*
|
|
80
|
+
* E.W1 Lane B (WhitePointColor lift): hoisted from the deleted
|
|
81
|
+
* `WhitePointColor<T>` intermediate class to the base. Optional with a
|
|
82
|
+
* D65 default — the historically D50 spaces (`LABColor`, `OKLABColor`)
|
|
83
|
+
* set `"D50"` explicitly in their constructors; `XYZColor` keeps the
|
|
84
|
+
* D65 default to mirror its prior `super(…, "D65")` call.
|
|
85
|
+
*
|
|
86
|
+
* Subclasses that don't carry a meaningful white point (HSL/HSV/HWB
|
|
87
|
+
* cylindrical, KelvinColor) leave it as the inherited default; reads
|
|
88
|
+
* are harmless and the field is monomorphic across all 14 subclasses
|
|
89
|
+
* (V8 hidden-class stable — verified by `bench/color-channel-access.mjs`).
|
|
90
|
+
*/
|
|
91
|
+
whitePoint: WhitePoint;
|
|
7
92
|
constructor(colorSpace: ColorSpace, alpha?: T);
|
|
93
|
+
/**
|
|
94
|
+
* The static channel-name list for this color space (e.g. `["r","g","b"]`
|
|
95
|
+
* for RGBColor). Subclasses override.
|
|
96
|
+
*/
|
|
97
|
+
abstract get channels(): readonly string[];
|
|
98
|
+
static _assertChannel(value: unknown): void;
|
|
99
|
+
private static _cloneDepth;
|
|
100
|
+
private static readonly CLONE_DEPTH_LIMIT;
|
|
8
101
|
toString(): string;
|
|
9
102
|
toFormattedString(digits?: number): string;
|
|
10
103
|
valueOf(): T[];
|
|
11
104
|
toJSON(): Record<string, T>;
|
|
12
105
|
clone(): this;
|
|
13
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Return the ordered list of channel keys followed by `"alpha"`.
|
|
108
|
+
*
|
|
109
|
+
* E.W1 Lane C — cached as a static-per-subclass `readonly` tuple
|
|
110
|
+
* (`channelKeysWithAlpha`). Pre-Lane-C this allocated a new array on every
|
|
111
|
+
* call via `[...this.channels, "alpha"]`; the demo gradient interpolation
|
|
112
|
+
* + `lerpColorValue` + `mixColors` + `normalizeColor` all hit this path
|
|
113
|
+
* per frame, so the per-call array churn was measurable.
|
|
114
|
+
*
|
|
115
|
+
* Subclasses define their own `static readonly channelKeysWithAlpha`
|
|
116
|
+
* (frozen tuple); the base falls back to a synthesized array for the
|
|
117
|
+
* abstract case (never reached in normal flow — there is no abstract
|
|
118
|
+
* `Color` instance — but kept for type safety).
|
|
119
|
+
*/
|
|
120
|
+
keys(): readonly string[];
|
|
14
121
|
values(): T[];
|
|
15
122
|
entries(): [string, T][];
|
|
16
|
-
protected getComponent(key: string): T | undefined;
|
|
17
|
-
protected setComponent(key: string, value: T): void;
|
|
18
|
-
}
|
|
19
|
-
declare class WhitePointColor<T = number> extends Color<T> {
|
|
20
|
-
whitePoint: WhitePoint;
|
|
21
|
-
constructor(colorSpace: ColorSpace, alpha: T, whitePoint: WhitePoint);
|
|
22
123
|
}
|
|
124
|
+
/** sRGB color space — the web's default. Components: r, g, b in [0,255] denormalized. D65 white point, ~2.2 gamma. */
|
|
23
125
|
export declare class RGBColor<T = number> extends Color<T> {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
set b(value: T);
|
|
126
|
+
static readonly channelKeysWithAlpha: readonly ["r", "g", "b", "alpha"];
|
|
127
|
+
r: ColorChannel<T>;
|
|
128
|
+
g: ColorChannel<T>;
|
|
129
|
+
b: ColorChannel<T>;
|
|
130
|
+
get channels(): readonly string[];
|
|
131
|
+
constructor(r?: T, g?: T, b?: T, alpha?: T);
|
|
31
132
|
}
|
|
133
|
+
/** HSL cylindrical space — hue [0,360], saturation [0,1], lightness [0,1]. D65 white point. */
|
|
32
134
|
export declare class HSLColor<T = number> extends Color<T> {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
set l(value: T);
|
|
135
|
+
static readonly channelKeysWithAlpha: readonly ["h", "s", "l", "alpha"];
|
|
136
|
+
h: ColorChannel<T>;
|
|
137
|
+
s: ColorChannel<T>;
|
|
138
|
+
l: ColorChannel<T>;
|
|
139
|
+
get channels(): readonly string[];
|
|
140
|
+
constructor(h?: T, s?: T, l?: T, alpha?: T);
|
|
40
141
|
}
|
|
142
|
+
/** HSV cylindrical space — hue [0,360], saturation [0,1], value [0,1]. D65 white point. */
|
|
41
143
|
export declare class HSVColor<T = number> extends Color<T> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
set v(value: T);
|
|
144
|
+
static readonly channelKeysWithAlpha: readonly ["h", "s", "v", "alpha"];
|
|
145
|
+
h: ColorChannel<T>;
|
|
146
|
+
s: ColorChannel<T>;
|
|
147
|
+
v: ColorChannel<T>;
|
|
148
|
+
get channels(): readonly string[];
|
|
149
|
+
constructor(h?: T, s?: T, v?: T, alpha?: T);
|
|
49
150
|
}
|
|
151
|
+
/** HWB space — hue [0,360], whiteness [0,1], blackness [0,1]. D65 white point. */
|
|
50
152
|
export declare class HWBColor<T = number> extends Color<T> {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
set b(value: T);
|
|
58
|
-
}
|
|
59
|
-
export declare class LABColor<T = number> extends WhitePointColor<T> {
|
|
60
|
-
constructor(l: T, a: T, b: T, alpha?: T);
|
|
61
|
-
get l(): T;
|
|
62
|
-
set l(value: T);
|
|
63
|
-
get a(): T;
|
|
64
|
-
set a(value: T);
|
|
65
|
-
get b(): T;
|
|
66
|
-
set b(value: T);
|
|
153
|
+
static readonly channelKeysWithAlpha: readonly ["h", "w", "b", "alpha"];
|
|
154
|
+
h: ColorChannel<T>;
|
|
155
|
+
w: ColorChannel<T>;
|
|
156
|
+
b: ColorChannel<T>;
|
|
157
|
+
get channels(): readonly string[];
|
|
158
|
+
constructor(h?: T, w?: T, b?: T, alpha?: T);
|
|
67
159
|
}
|
|
160
|
+
/** CIE Lab (D50) — perceptual lightness L [0,100], a/b axes [-125,125]. */
|
|
161
|
+
export declare class LABColor<T = number> extends Color<T> {
|
|
162
|
+
static readonly channelKeysWithAlpha: readonly ["l", "a", "b", "alpha"];
|
|
163
|
+
l: ColorChannel<T>;
|
|
164
|
+
a: ColorChannel<T>;
|
|
165
|
+
b: ColorChannel<T>;
|
|
166
|
+
get channels(): readonly string[];
|
|
167
|
+
constructor(l?: T, a?: T, b?: T, alpha?: T);
|
|
168
|
+
}
|
|
169
|
+
/** CIE LCH (D50) — cylindrical form of Lab. L [0,100], C [0,150], H [0,360]. */
|
|
68
170
|
export declare class LCHColor<T = number> extends Color<T> {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
export declare class OKLABColor<T = number> extends
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
set b(value: T);
|
|
171
|
+
static readonly channelKeysWithAlpha: readonly ["l", "c", "h", "alpha"];
|
|
172
|
+
l: ColorChannel<T>;
|
|
173
|
+
c: ColorChannel<T>;
|
|
174
|
+
h: ColorChannel<T>;
|
|
175
|
+
get channels(): readonly string[];
|
|
176
|
+
constructor(l?: T, c?: T, h?: T, alpha?: T);
|
|
177
|
+
}
|
|
178
|
+
/** OKLab (D50) — perceptually uniform. L [0,1], a/b [-0.4,0.4]. Björn Ottosson's improvement over CIE Lab. */
|
|
179
|
+
export declare class OKLABColor<T = number> extends Color<T> {
|
|
180
|
+
static readonly channelKeysWithAlpha: readonly ["l", "a", "b", "alpha"];
|
|
181
|
+
l: ColorChannel<T>;
|
|
182
|
+
a: ColorChannel<T>;
|
|
183
|
+
b: ColorChannel<T>;
|
|
184
|
+
get channels(): readonly string[];
|
|
185
|
+
constructor(l?: T, a?: T, b?: T, alpha?: T);
|
|
85
186
|
}
|
|
187
|
+
/** OKLCH — cylindrical form of OKLab. L [0,1], C [0,0.4], H [0,360]. CSS Color Level 4 recommended space. */
|
|
86
188
|
export declare class OKLCHColor<T = number> extends Color<T> {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export declare class XYZColor<T = number> extends
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
set z(value: T);
|
|
189
|
+
static readonly channelKeysWithAlpha: readonly ["l", "c", "h", "alpha"];
|
|
190
|
+
l: ColorChannel<T>;
|
|
191
|
+
c: ColorChannel<T>;
|
|
192
|
+
h: ColorChannel<T>;
|
|
193
|
+
get channels(): readonly string[];
|
|
194
|
+
constructor(l?: T, c?: T, h?: T, alpha?: T);
|
|
195
|
+
}
|
|
196
|
+
/** CIE XYZ (D65) — the connection space hub for all conversions. Unbounded components. */
|
|
197
|
+
export declare class XYZColor<T = number> extends Color<T> {
|
|
198
|
+
static readonly channelKeysWithAlpha: readonly ["x", "y", "z", "alpha"];
|
|
199
|
+
x: ColorChannel<T>;
|
|
200
|
+
y: ColorChannel<T>;
|
|
201
|
+
z: ColorChannel<T>;
|
|
202
|
+
get channels(): readonly string[];
|
|
203
|
+
constructor(x?: T, y?: T, z?: T, alpha?: T);
|
|
103
204
|
}
|
|
205
|
+
/** Color temperature — single kelvin component [1000,40000]. Converts through blackbody radiation to sRGB. */
|
|
104
206
|
export declare class KelvinColor<T = number> extends Color<T> {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
207
|
+
static readonly channelKeysWithAlpha: readonly ["kelvin", "alpha"];
|
|
208
|
+
kelvin: ColorChannel<T>;
|
|
209
|
+
get channels(): readonly string[];
|
|
210
|
+
constructor(kelvin?: T, alpha?: T);
|
|
108
211
|
}
|
|
212
|
+
/** Linear-light sRGB — no gamma curve. Components r, g, b in [0,1]. D65 white point. */
|
|
109
213
|
export declare class LinearSRGBColor<T = number> extends Color<T> {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
set b(value: T);
|
|
214
|
+
static readonly channelKeysWithAlpha: readonly ["r", "g", "b", "alpha"];
|
|
215
|
+
r: ColorChannel<T>;
|
|
216
|
+
g: ColorChannel<T>;
|
|
217
|
+
b: ColorChannel<T>;
|
|
218
|
+
get channels(): readonly string[];
|
|
219
|
+
constructor(r?: T, g?: T, b?: T, alpha?: T);
|
|
117
220
|
}
|
|
221
|
+
/** Display P3 — wide-gamut space used by Apple displays. Components r, g, b in [0,1]. D65, sRGB transfer. */
|
|
118
222
|
export declare class DisplayP3Color<T = number> extends Color<T> {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
set b(value: T);
|
|
223
|
+
static readonly channelKeysWithAlpha: readonly ["r", "g", "b", "alpha"];
|
|
224
|
+
r: ColorChannel<T>;
|
|
225
|
+
g: ColorChannel<T>;
|
|
226
|
+
b: ColorChannel<T>;
|
|
227
|
+
get channels(): readonly string[];
|
|
228
|
+
constructor(r?: T, g?: T, b?: T, alpha?: T);
|
|
126
229
|
}
|
|
230
|
+
/** Adobe RGB (1998) — wide-gamut space for print/photography. Components r, g, b in [0,1]. D65, gamma 2.2. */
|
|
127
231
|
export declare class AdobeRGBColor<T = number> extends Color<T> {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
set b(value: T);
|
|
232
|
+
static readonly channelKeysWithAlpha: readonly ["r", "g", "b", "alpha"];
|
|
233
|
+
r: ColorChannel<T>;
|
|
234
|
+
g: ColorChannel<T>;
|
|
235
|
+
b: ColorChannel<T>;
|
|
236
|
+
get channels(): readonly string[];
|
|
237
|
+
constructor(r?: T, g?: T, b?: T, alpha?: T);
|
|
135
238
|
}
|
|
239
|
+
/** ProPhoto RGB (ROMM) — ultra-wide gamut for photography. Components r, g, b in [0,1]. D50, gamma 1.8. */
|
|
136
240
|
export declare class ProPhotoRGBColor<T = number> extends Color<T> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
set b(value: T);
|
|
241
|
+
static readonly channelKeysWithAlpha: readonly ["r", "g", "b", "alpha"];
|
|
242
|
+
r: ColorChannel<T>;
|
|
243
|
+
g: ColorChannel<T>;
|
|
244
|
+
b: ColorChannel<T>;
|
|
245
|
+
get channels(): readonly string[];
|
|
246
|
+
constructor(r?: T, g?: T, b?: T, alpha?: T);
|
|
144
247
|
}
|
|
248
|
+
/** ITU-R BT.2020 — HDR/UHD broadcast gamut. Components r, g, b in [0,1]. D65, PQ transfer. */
|
|
145
249
|
export declare class Rec2020Color<T = number> extends Color<T> {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
set b(value: T);
|
|
250
|
+
static readonly channelKeysWithAlpha: readonly ["r", "g", "b", "alpha"];
|
|
251
|
+
r: ColorChannel<T>;
|
|
252
|
+
g: ColorChannel<T>;
|
|
253
|
+
b: ColorChannel<T>;
|
|
254
|
+
get channels(): readonly string[];
|
|
255
|
+
constructor(r?: T, g?: T, b?: T, alpha?: T);
|
|
153
256
|
}
|
|
154
257
|
export type ColorSpaceMap<T> = {
|
|
155
258
|
rgb: RGBColor<T>;
|
|
@@ -168,4 +271,5 @@ export type ColorSpaceMap<T> = {
|
|
|
168
271
|
"prophoto-rgb": ProPhotoRGBColor<T>;
|
|
169
272
|
rec2020: Rec2020Color<T>;
|
|
170
273
|
};
|
|
171
|
-
export {};
|
|
274
|
+
export { getFormattedColorSpaceRange, color2, gamutMap, interpolateHue, mixColors, CYLINDRICAL_HUE_COMPONENT, computeSafeAccent, safeAccentColor, needsContrastAdjustment, getOklchLightness, hex2rgb, rgb2hex, } from './dispatch';
|
|
275
|
+
export type { HueInterpolationMethod } from './dispatch';
|