color-bits 1.1.1 → 1.2.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/.claude/settings.local.json +9 -0
- package/README.md +29 -13
- package/benchmarks/compare-oklab.ts +44 -0
- package/benchmarks/compare-srgb.ts +59 -0
- package/benchmarks/compare.ts +46 -0
- package/benchmarks/parse.ts +41 -0
- package/build/conversion/channels.d.ts +61 -0
- package/build/conversion/channels.js +353 -0
- package/build/conversion/channels.js.map +1 -0
- package/build/{convert.d.ts → conversion/color-spaces.d.ts} +25 -23
- package/build/conversion/color-spaces.js +263 -0
- package/build/conversion/color-spaces.js.map +1 -0
- package/build/core/bits.d.ts +28 -0
- package/build/{core.js → core/bits.js} +25 -26
- package/build/core/bits.js.map +1 -0
- package/build/core/bytes.d.ts +5 -0
- package/build/core/bytes.js +12 -0
- package/build/core/bytes.js.map +1 -0
- package/build/css.d.ts +1 -0
- package/build/css.js +18 -0
- package/build/css.js.map +1 -0
- package/build/formatting/index.d.ts +27 -0
- package/build/{format.js → formatting/index.js} +13 -67
- package/build/formatting/index.js.map +1 -0
- package/build/index.d.ts +6 -4
- package/build/index.js +6 -4
- package/build/index.js.map +1 -1
- package/build/namedColors.d.ts +1 -0
- package/build/namedColors.js +18 -0
- package/build/namedColors.js.map +1 -0
- package/build/operations/adjust.d.ts +19 -0
- package/build/operations/adjust.js +40 -0
- package/build/operations/adjust.js.map +1 -0
- package/build/operations/blend.d.ts +9 -0
- package/build/operations/blend.js +19 -0
- package/build/operations/blend.js.map +1 -0
- package/build/operations/color-mix.d.ts +20 -0
- package/build/operations/color-mix.js +144 -0
- package/build/operations/color-mix.js.map +1 -0
- package/build/operations/luminance.d.ts +7 -0
- package/build/operations/luminance.js +20 -0
- package/build/operations/luminance.js.map +1 -0
- package/build/parsing/calc.d.ts +8 -0
- package/build/parsing/calc.js +205 -0
- package/build/parsing/calc.js.map +1 -0
- package/build/parsing/color-mix.d.ts +8 -0
- package/build/parsing/color-mix.js +70 -0
- package/build/parsing/color-mix.js.map +1 -0
- package/build/parsing/css.d.ts +23 -0
- package/build/parsing/css.js +115 -0
- package/build/parsing/css.js.map +1 -0
- package/build/parsing/fast.d.ts +19 -0
- package/build/parsing/fast.js +184 -0
- package/build/parsing/fast.js.map +1 -0
- package/build/parsing/named-colors.d.ts +12 -0
- package/build/parsing/named-colors.js +68 -0
- package/build/parsing/named-colors.js.map +1 -0
- package/build/parsing/relative.d.ts +9 -0
- package/build/parsing/relative.js +158 -0
- package/build/parsing/relative.js.map +1 -0
- package/build/parsing/tokenizer.d.ts +16 -0
- package/build/parsing/tokenizer.js +78 -0
- package/build/parsing/tokenizer.js.map +1 -0
- package/build/parsing/values.d.ts +41 -0
- package/build/parsing/values.js +139 -0
- package/build/parsing/values.js.map +1 -0
- package/package.json +15 -3
- package/benchmarks/index.ts +0 -35
- package/build/bit.d.ts +0 -3
- package/build/bit.js +0 -29
- package/build/bit.js.map +0 -1
- package/build/convert.js +0 -347
- package/build/convert.js.map +0 -1
- package/build/core.d.ts +0 -27
- package/build/core.js.map +0 -1
- package/build/format.d.ts +0 -27
- package/build/format.js.map +0 -1
- package/build/functions.d.ts +0 -33
- package/build/functions.js +0 -95
- package/build/functions.js.map +0 -1
- package/build/parse.d.ts +0 -17
- package/build/parse.js +0 -392
- package/build/parse.js.map +0 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ColorBits } from '../core/bits';
|
|
2
|
+
/**
|
|
3
|
+
* Modifies color alpha channel.
|
|
4
|
+
* @param color - ColorBits
|
|
5
|
+
* @param value - Value in the range [0, 1]
|
|
6
|
+
*/
|
|
7
|
+
export declare function alpha(color: ColorBits, value: number): ColorBits;
|
|
8
|
+
/**
|
|
9
|
+
* Darkens a color.
|
|
10
|
+
* @param color - ColorBits
|
|
11
|
+
* @param coefficient - Multiplier in the range [0, 1]
|
|
12
|
+
*/
|
|
13
|
+
export declare function darken(color: ColorBits, coefficient: number): ColorBits;
|
|
14
|
+
/**
|
|
15
|
+
* Lighten a color.
|
|
16
|
+
* @param color - ColorBits
|
|
17
|
+
* @param coefficient - Multiplier in the range [0, 1]
|
|
18
|
+
*/
|
|
19
|
+
export declare function lighten(color: ColorBits, coefficient: number): ColorBits;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.alpha = alpha;
|
|
4
|
+
exports.darken = darken;
|
|
5
|
+
exports.lighten = lighten;
|
|
6
|
+
const bits_1 = require("../core/bits");
|
|
7
|
+
/**
|
|
8
|
+
* Modifies color alpha channel.
|
|
9
|
+
* @param color - ColorBits
|
|
10
|
+
* @param value - Value in the range [0, 1]
|
|
11
|
+
*/
|
|
12
|
+
function alpha(color, value) {
|
|
13
|
+
return (0, bits_1.setAlpha)(color, Math.round(value * 255));
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Darkens a color.
|
|
17
|
+
* @param color - ColorBits
|
|
18
|
+
* @param coefficient - Multiplier in the range [0, 1]
|
|
19
|
+
*/
|
|
20
|
+
function darken(color, coefficient) {
|
|
21
|
+
const r = (0, bits_1.getRed)(color);
|
|
22
|
+
const g = (0, bits_1.getGreen)(color);
|
|
23
|
+
const b = (0, bits_1.getBlue)(color);
|
|
24
|
+
const a = (0, bits_1.getAlpha)(color);
|
|
25
|
+
const factor = 1 - coefficient;
|
|
26
|
+
return (0, bits_1.newColor)(r * factor, g * factor, b * factor, a);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Lighten a color.
|
|
30
|
+
* @param color - ColorBits
|
|
31
|
+
* @param coefficient - Multiplier in the range [0, 1]
|
|
32
|
+
*/
|
|
33
|
+
function lighten(color, coefficient) {
|
|
34
|
+
const r = (0, bits_1.getRed)(color);
|
|
35
|
+
const g = (0, bits_1.getGreen)(color);
|
|
36
|
+
const b = (0, bits_1.getBlue)(color);
|
|
37
|
+
const a = (0, bits_1.getAlpha)(color);
|
|
38
|
+
return (0, bits_1.newColor)(r + (255 - r) * coefficient, g + (255 - g) * coefficient, b + (255 - b) * coefficient, a);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=adjust.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adjust.js","sourceRoot":"","sources":["../../src/operations/adjust.ts"],"names":[],"mappings":";;AAQA,sBAEC;AAOD,wBAcC;AAOD,0BAYC;AAjDD,uCAAsF;AAEtF;;;;GAIG;AACH,SAAgB,KAAK,CAAC,KAAgB,EAAE,KAAa;IACnD,OAAO,IAAA,eAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAA;AACjD,CAAC;AAED;;;;GAIG;AACH,SAAgB,MAAM,CAAC,KAAgB,EAAE,WAAmB;IAC1D,MAAM,CAAC,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,CAAA;IACvB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAA;IACzB,MAAM,CAAC,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAA;IACxB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAA;IAEzB,MAAM,MAAM,GAAG,CAAC,GAAG,WAAW,CAAA;IAE9B,OAAO,IAAA,eAAQ,EACb,CAAC,GAAG,MAAM,EACV,CAAC,GAAG,MAAM,EACV,CAAC,GAAG,MAAM,EACV,CAAC,CACF,CAAA;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,OAAO,CAAC,KAAgB,EAAE,WAAmB;IAC3D,MAAM,CAAC,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,CAAA;IACvB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAA;IACzB,MAAM,CAAC,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,CAAA;IACxB,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,CAAA;IAEzB,OAAO,IAAA,eAAQ,EACb,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,WAAW,EAC3B,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,WAAW,EAC3B,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,WAAW,EAC3B,CAAC,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ColorBits } from '../core/bits';
|
|
2
|
+
/**
|
|
3
|
+
* Blend (aka mix) two colors together.
|
|
4
|
+
* @param background The background color
|
|
5
|
+
* @param overlay The overlay color affected by `opacity`
|
|
6
|
+
* @param opacity Opacity (alpha) for `overlay`
|
|
7
|
+
* @param [gamma=1.0] Gamma correction coefficient. `1.0` to match browser behavior, `2.2` for gamma-corrected blending.
|
|
8
|
+
*/
|
|
9
|
+
export declare function blend(background: ColorBits, overlay: ColorBits, opacity: number, gamma?: number): ColorBits;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.blend = blend;
|
|
4
|
+
const bits_1 = require("../core/bits");
|
|
5
|
+
/**
|
|
6
|
+
* Blend (aka mix) two colors together.
|
|
7
|
+
* @param background The background color
|
|
8
|
+
* @param overlay The overlay color affected by `opacity`
|
|
9
|
+
* @param opacity Opacity (alpha) for `overlay`
|
|
10
|
+
* @param [gamma=1.0] Gamma correction coefficient. `1.0` to match browser behavior, `2.2` for gamma-corrected blending.
|
|
11
|
+
*/
|
|
12
|
+
function blend(background, overlay, opacity, gamma = 1.0) {
|
|
13
|
+
const blendChannel = (b, o) => Math.round((b ** (1 / gamma) * (1 - opacity) + o ** (1 / gamma) * opacity) ** gamma);
|
|
14
|
+
const r = blendChannel((0, bits_1.getRed)(background), (0, bits_1.getRed)(overlay));
|
|
15
|
+
const g = blendChannel((0, bits_1.getGreen)(background), (0, bits_1.getGreen)(overlay));
|
|
16
|
+
const b = blendChannel((0, bits_1.getBlue)(background), (0, bits_1.getBlue)(overlay));
|
|
17
|
+
return (0, bits_1.newColor)(r, g, b, 255);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=blend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blend.js","sourceRoot":"","sources":["../../src/operations/blend.ts"],"names":[],"mappings":";;AAUA,sBASC;AAlBD,uCAAkE;AAElE;;;;;;GAMG;AACH,SAAgB,KAAK,CAAC,UAAqB,EAAE,OAAkB,EAAE,OAAe,EAAE,KAAK,GAAG,GAAG;IAC3F,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAC5C,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,IAAI,KAAK,CAAC,CAAA;IAEtF,MAAM,CAAC,GAAG,YAAY,CAAC,IAAA,aAAM,EAAC,UAAU,CAAC,EAAE,IAAA,aAAM,EAAC,OAAO,CAAC,CAAC,CAAA;IAC3D,MAAM,CAAC,GAAG,YAAY,CAAC,IAAA,eAAQ,EAAC,UAAU,CAAC,EAAE,IAAA,eAAQ,EAAC,OAAO,CAAC,CAAC,CAAA;IAC/D,MAAM,CAAC,GAAG,YAAY,CAAC,IAAA,cAAO,EAAC,UAAU,CAAC,EAAE,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC,CAAA;IAE7D,OAAO,IAAA,eAAQ,EAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ColorBits } from '../core/bits';
|
|
2
|
+
import type { ColorModel } from '../conversion/channels';
|
|
3
|
+
export type HueMethod = 'shorter' | 'longer' | 'increasing' | 'decreasing';
|
|
4
|
+
export interface ColorMixOptions {
|
|
5
|
+
/** interpolation space: a model name ("oklab", "hsl", …) or a ColorModel, e.g. colorSpaceModel('srgb') */
|
|
6
|
+
space: string | ColorModel;
|
|
7
|
+
/** hue interpolation method for polar spaces (default "shorter") */
|
|
8
|
+
hue?: HueMethod;
|
|
9
|
+
/** percentage (0..100) of color1; defaults derived from p2 or 50 */
|
|
10
|
+
p1?: number;
|
|
11
|
+
/** percentage (0..100) of color2; defaults derived from p1 or 50 */
|
|
12
|
+
p2?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Mix two colors in the given color space.
|
|
16
|
+
* @param color1 first color
|
|
17
|
+
* @param color2 second color
|
|
18
|
+
* @param options interpolation space, hue method and percentages
|
|
19
|
+
*/
|
|
20
|
+
export declare function colorMix(color1: ColorBits, color2: ColorBits, options: ColorMixOptions): ColorBits;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// CSS Color 5 color-mix(). Interpolates two colors in a chosen color space with
|
|
3
|
+
// premultiplied alpha and the four hue-interpolation methods.
|
|
4
|
+
// https://drafts.csswg.org/css-color-5/#color-mix
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.colorMix = colorMix;
|
|
7
|
+
const bits_1 = require("../core/bits");
|
|
8
|
+
const bytes_1 = require("../core/bytes");
|
|
9
|
+
const channels_1 = require("../conversion/channels");
|
|
10
|
+
// Both interpolation endpoints are alive at once, so each gets its own buffer.
|
|
11
|
+
const CHANNELS_1 = new Float64Array(3);
|
|
12
|
+
const CHANNELS_2 = new Float64Array(3);
|
|
13
|
+
function fail(message) {
|
|
14
|
+
throw new Error('color-mix(): ' + message);
|
|
15
|
+
}
|
|
16
|
+
function normalizeHue(h) {
|
|
17
|
+
return ((h % 360) + 360) % 360;
|
|
18
|
+
}
|
|
19
|
+
function adjustHue(h1, h2, method) {
|
|
20
|
+
h1 = normalizeHue(h1);
|
|
21
|
+
h2 = normalizeHue(h2);
|
|
22
|
+
const d = h2 - h1;
|
|
23
|
+
switch (method) {
|
|
24
|
+
case 'shorter':
|
|
25
|
+
if (d > 180)
|
|
26
|
+
h1 += 360;
|
|
27
|
+
else if (d < -180)
|
|
28
|
+
h2 += 360;
|
|
29
|
+
break;
|
|
30
|
+
case 'longer':
|
|
31
|
+
if (d > 0 && d < 180)
|
|
32
|
+
h1 += 360;
|
|
33
|
+
else if (d > -180 && d <= 0)
|
|
34
|
+
h2 += 360;
|
|
35
|
+
break;
|
|
36
|
+
case 'increasing':
|
|
37
|
+
if (h2 < h1)
|
|
38
|
+
h2 += 360;
|
|
39
|
+
break;
|
|
40
|
+
case 'decreasing':
|
|
41
|
+
if (h1 < h2)
|
|
42
|
+
h1 += 360;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return [h1, h2];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Mix two colors in the given color space.
|
|
49
|
+
* @param color1 first color
|
|
50
|
+
* @param color2 second color
|
|
51
|
+
* @param options interpolation space, hue method and percentages
|
|
52
|
+
*/
|
|
53
|
+
function colorMix(color1, color2, options) {
|
|
54
|
+
const { space } = options;
|
|
55
|
+
const model = typeof space === 'string' ? (0, channels_1.colorModel)(space.toLowerCase()) : space;
|
|
56
|
+
if (model === null) {
|
|
57
|
+
fail(`unsupported color space: "${space}"`);
|
|
58
|
+
}
|
|
59
|
+
const hueIndex = model.hues.indexOf(true);
|
|
60
|
+
if (options.hue !== undefined && hueIndex === -1) {
|
|
61
|
+
fail('hue method requires a polar space');
|
|
62
|
+
}
|
|
63
|
+
const method = options.hue ?? 'shorter';
|
|
64
|
+
// Resolve percentages and the (sub-100%) alpha multiplier.
|
|
65
|
+
// https://drafts.csswg.org/css-color-5/#color-mix-percent-norm
|
|
66
|
+
const o1 = options.p1;
|
|
67
|
+
const o2 = options.p2;
|
|
68
|
+
if ((o1 !== undefined && !(o1 >= 0 && o1 <= 100)) || (o2 !== undefined && !(o2 >= 0 && o2 <= 100))) {
|
|
69
|
+
fail('percentages must be within [0%, 100%]');
|
|
70
|
+
}
|
|
71
|
+
let p1;
|
|
72
|
+
let p2;
|
|
73
|
+
let alphaMultiplier = 1;
|
|
74
|
+
if (o1 === undefined && o2 === undefined) {
|
|
75
|
+
p1 = 50;
|
|
76
|
+
p2 = 50;
|
|
77
|
+
}
|
|
78
|
+
else if (o1 === undefined) {
|
|
79
|
+
p2 = o2;
|
|
80
|
+
p1 = 100 - p2;
|
|
81
|
+
}
|
|
82
|
+
else if (o2 === undefined) {
|
|
83
|
+
p1 = o1;
|
|
84
|
+
p2 = 100 - p1;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const sum = o1 + o2;
|
|
88
|
+
if (sum === 0) {
|
|
89
|
+
fail('percentages must not sum to zero');
|
|
90
|
+
}
|
|
91
|
+
if (sum < 100) {
|
|
92
|
+
alphaMultiplier = sum / 100;
|
|
93
|
+
}
|
|
94
|
+
p1 = (o1 / sum) * 100;
|
|
95
|
+
p2 = (o2 / sum) * 100;
|
|
96
|
+
}
|
|
97
|
+
const w1 = p1 / 100;
|
|
98
|
+
const w2 = p2 / 100;
|
|
99
|
+
const r1 = (0, bits_1.getRed)(color1), g1 = (0, bits_1.getGreen)(color1), b1 = (0, bits_1.getBlue)(color1);
|
|
100
|
+
const r2 = (0, bits_1.getRed)(color2), g2 = (0, bits_1.getGreen)(color2), b2 = (0, bits_1.getBlue)(color2);
|
|
101
|
+
const a1 = (0, bits_1.getAlpha)(color1) / 255;
|
|
102
|
+
const a2 = (0, bits_1.getAlpha)(color2) / 255;
|
|
103
|
+
const c1 = model.fromSrgb(r1 / 255, g1 / 255, b1 / 255, CHANNELS_1);
|
|
104
|
+
const c2 = model.fromSrgb(r2 / 255, g2 / 255, b2 / 255, CHANNELS_2);
|
|
105
|
+
const hi = hueIndex;
|
|
106
|
+
if (hi >= 0) {
|
|
107
|
+
// A powerless hue (achromatic color) is treated as missing and takes the
|
|
108
|
+
// other color's hue. https://drafts.csswg.org/css-color-4/#interpolation-missing
|
|
109
|
+
// Achromaticity is detected on the sRGB bytes (exact); the converted
|
|
110
|
+
// channels carry conversion noise (e.g. white -> lch chroma ~0.02).
|
|
111
|
+
const missing1 = r1 === g1 && g1 === b1;
|
|
112
|
+
const missing2 = r2 === g2 && g2 === b2;
|
|
113
|
+
if (missing1 && !missing2) {
|
|
114
|
+
c1[hi] = c2[hi];
|
|
115
|
+
}
|
|
116
|
+
else if (missing2 && !missing1) {
|
|
117
|
+
c2[hi] = c1[hi];
|
|
118
|
+
}
|
|
119
|
+
const [h1, h2] = adjustHue(c1[hi], c2[hi], method);
|
|
120
|
+
c1[hi] = h1;
|
|
121
|
+
c2[hi] = h2;
|
|
122
|
+
}
|
|
123
|
+
// Premultiply every non-hue coordinate by its alpha.
|
|
124
|
+
for (let i = 0; i < 3; i++) {
|
|
125
|
+
if (i !== hi) {
|
|
126
|
+
c1[i] *= a1;
|
|
127
|
+
c2[i] *= a2;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const mixedAlpha = a1 * w1 + a2 * w2;
|
|
131
|
+
for (let i = 0; i < 3; i++) {
|
|
132
|
+
let v = c1[i] * w1 + c2[i] * w2;
|
|
133
|
+
if (i === hi) {
|
|
134
|
+
v = normalizeHue(v);
|
|
135
|
+
}
|
|
136
|
+
else if (mixedAlpha !== 0) {
|
|
137
|
+
v /= mixedAlpha; // un-premultiply
|
|
138
|
+
}
|
|
139
|
+
c1[i] = v;
|
|
140
|
+
}
|
|
141
|
+
const alphaByte = (0, bytes_1.clampByte)(mixedAlpha * alphaMultiplier * 255);
|
|
142
|
+
return model.toColor(c1[0], c1[1], c1[2], alphaByte);
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=color-mix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-mix.js","sourceRoot":"","sources":["../../src/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,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACb,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;YACX,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;QACb,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;IACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3B,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;QAC/B,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;YACb,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAA;QACrB,CAAC;aAAM,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YAC5B,CAAC,IAAI,UAAU,CAAA,CAAC,iBAAiB;QACnC,CAAC;QACD,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;IACX,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,iBAAS,EAAC,UAAU,GAAG,eAAe,GAAG,GAAG,CAAC,CAAA;IAC/D,OAAO,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;AACtD,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ColorBits } from '../core/bits';
|
|
2
|
+
/**
|
|
3
|
+
* The relative brightness of any point in a color space, normalized to 0 for
|
|
4
|
+
* darkest black and 1 for lightest white.
|
|
5
|
+
* @returns The relative brightness of the color in the range 0 - 1, with 3 digits precision
|
|
6
|
+
*/
|
|
7
|
+
export declare function getLuminance(color: ColorBits): number;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLuminance = getLuminance;
|
|
4
|
+
const bits_1 = require("../core/bits");
|
|
5
|
+
/**
|
|
6
|
+
* The relative brightness of any point in a color space, normalized to 0 for
|
|
7
|
+
* darkest black and 1 for lightest white.
|
|
8
|
+
* @returns The relative brightness of the color in the range 0 - 1, with 3 digits precision
|
|
9
|
+
*/
|
|
10
|
+
function getLuminance(color) {
|
|
11
|
+
const r = (0, bits_1.getRed)(color) / 255;
|
|
12
|
+
const g = (0, bits_1.getGreen)(color) / 255;
|
|
13
|
+
const b = (0, bits_1.getBlue)(color) / 255;
|
|
14
|
+
const apply = (v) => v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
15
|
+
const r1 = apply(r);
|
|
16
|
+
const g1 = apply(g);
|
|
17
|
+
const b1 = apply(b);
|
|
18
|
+
return Math.round((0.2126 * r1 + 0.7152 * g1 + 0.0722 * b1) * 1000) / 1000;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=luminance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"luminance.js","sourceRoot":"","sources":["../../src/operations/luminance.ts"],"names":[],"mappings":";;AAQA,oCAYC;AAnBD,uCAAwD;AAExD;;;;GAIG;AACH,SAAgB,YAAY,CAAC,KAAgB;IAC3C,MAAM,CAAC,GAAG,IAAA,aAAM,EAAC,KAAK,CAAC,GAAG,GAAG,CAAA;IAC7B,MAAM,CAAC,GAAG,IAAA,eAAQ,EAAC,KAAK,CAAC,GAAG,GAAG,CAAA;IAC/B,MAAM,CAAC,GAAG,IAAA,cAAO,EAAC,KAAK,CAAC,GAAG,GAAG,CAAA;IAE9B,MAAM,KAAK,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC,IAAI,GAAG,CAAA;IAEpF,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IACnB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IACnB,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;IAEnB,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,EAAE,GAAG,MAAM,GAAG,EAAE,GAAG,MAAM,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;AAC5E,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Evaluate a calc() expression against channel keyword bindings.
|
|
3
|
+
* @param body the expression, with or without the outer `calc(` `)`, e.g.
|
|
4
|
+
* "calc(l * 0.8)" or "l * 0.8"; nested calc() is supported
|
|
5
|
+
* @param scope channel keyword bindings
|
|
6
|
+
* @param range percentage reference for the destination channel
|
|
7
|
+
*/
|
|
8
|
+
export declare function evaluateCalc(body: string, scope: Map<string, number>, range: number): number;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Minimal CSS calc() evaluator for relative-color channel expressions, e.g.
|
|
3
|
+
// `calc(l * 0.8)`, `calc(h + 120)`, `calc((r + g) / 2)`. Supports + - * /, unary
|
|
4
|
+
// +/-, parentheses, nested calc(), numbers, percentages and angle dimensions.
|
|
5
|
+
//
|
|
6
|
+
// Identifiers are channel keywords resolved from `scope` (e.g. r, g, b, l, h,
|
|
7
|
+
// alpha). Percentages resolve against `range` — the destination channel's
|
|
8
|
+
// reference (e.g. 255 for rgb, 1 for oklab lightness) — matching how a bare
|
|
9
|
+
// percentage is interpreted in that channel slot.
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.evaluateCalc = evaluateCalc;
|
|
12
|
+
const ZERO = 48; // '0'
|
|
13
|
+
const NINE = 57; // '9'
|
|
14
|
+
const DOT = 46; // '.'
|
|
15
|
+
const PERCENT = 37; // '%'
|
|
16
|
+
function isDigit(c) {
|
|
17
|
+
return (c >= ZERO && c <= NINE) || c === DOT;
|
|
18
|
+
}
|
|
19
|
+
function isAlpha(c) {
|
|
20
|
+
// a-z, A-Z (identifiers like `alpha`, channel letters, angle units)
|
|
21
|
+
return (c >= 97 && c <= 122) || (c >= 65 && c <= 90);
|
|
22
|
+
}
|
|
23
|
+
const ANGLE_TO_DEG = {
|
|
24
|
+
deg: 1,
|
|
25
|
+
grad: 360 / 400,
|
|
26
|
+
rad: 180 / Math.PI,
|
|
27
|
+
turn: 360,
|
|
28
|
+
};
|
|
29
|
+
/** A complete CSS <number>: the lexer's digit scan can overshoot (e.g. "1.2.3", "2e"). */
|
|
30
|
+
const NUMBER = /^(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i;
|
|
31
|
+
function fail(message, input) {
|
|
32
|
+
throw new Error(`calc(): ${message} in "${input}"`);
|
|
33
|
+
}
|
|
34
|
+
function lex(input, range) {
|
|
35
|
+
const tokens = [];
|
|
36
|
+
let i = 0;
|
|
37
|
+
const n = input.length;
|
|
38
|
+
while (i < n) {
|
|
39
|
+
const c = input.charCodeAt(i);
|
|
40
|
+
if (c === 32 || c === 9 || c === 10 || c === 13) { // whitespace
|
|
41
|
+
i++;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (c === 40) {
|
|
45
|
+
tokens.push({ t: 'lparen' });
|
|
46
|
+
i++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (c === 41) {
|
|
50
|
+
tokens.push({ t: 'rparen' });
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (c === 43 || c === 45 || c === 42 || c === 47) { // + - * /
|
|
55
|
+
tokens.push({ t: 'op', v: input[i] });
|
|
56
|
+
i++;
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (isDigit(c)) {
|
|
60
|
+
let j = i + 1;
|
|
61
|
+
while (j < n && isDigit(input.charCodeAt(j)))
|
|
62
|
+
j++;
|
|
63
|
+
// scientific notation (e.g. 1e-3)
|
|
64
|
+
if (j < n && (input.charCodeAt(j) === 101 || input.charCodeAt(j) === 69)) {
|
|
65
|
+
j++;
|
|
66
|
+
if (j < n && (input.charCodeAt(j) === 43 || input.charCodeAt(j) === 45))
|
|
67
|
+
j++;
|
|
68
|
+
while (j < n && isDigit(input.charCodeAt(j)))
|
|
69
|
+
j++;
|
|
70
|
+
}
|
|
71
|
+
const raw = input.slice(i, j);
|
|
72
|
+
if (!NUMBER.test(raw)) {
|
|
73
|
+
fail(`invalid number "${raw}"`, input);
|
|
74
|
+
}
|
|
75
|
+
let value = parseFloat(raw);
|
|
76
|
+
i = j;
|
|
77
|
+
// trailing unit: % or angle
|
|
78
|
+
if (i < n && input.charCodeAt(i) === PERCENT) {
|
|
79
|
+
value = (value / 100) * range;
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
let u = i;
|
|
84
|
+
while (u < n && isAlpha(input.charCodeAt(u)))
|
|
85
|
+
u++;
|
|
86
|
+
if (u > i) {
|
|
87
|
+
const unit = input.slice(i, u).toLowerCase();
|
|
88
|
+
const factor = ANGLE_TO_DEG[unit];
|
|
89
|
+
if (factor !== undefined) {
|
|
90
|
+
value *= factor;
|
|
91
|
+
i = u;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
tokens.push({ t: 'num', v: value });
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (isAlpha(c)) {
|
|
99
|
+
let j = i + 1;
|
|
100
|
+
while (j < n && isAlpha(input.charCodeAt(j)))
|
|
101
|
+
j++;
|
|
102
|
+
const id = input.slice(i, j).toLowerCase();
|
|
103
|
+
i = j;
|
|
104
|
+
// `calc(` (outer and nested) reads as a plain parenthesis
|
|
105
|
+
if (id === 'calc' && i < n && input.charCodeAt(i) === 40) {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
tokens.push({ t: 'id', v: id });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
fail(`unexpected character "${input[i]}"`, input);
|
|
112
|
+
}
|
|
113
|
+
return tokens;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Evaluate a calc() expression against channel keyword bindings.
|
|
117
|
+
* @param body the expression, with or without the outer `calc(` `)`, e.g.
|
|
118
|
+
* "calc(l * 0.8)" or "l * 0.8"; nested calc() is supported
|
|
119
|
+
* @param scope channel keyword bindings
|
|
120
|
+
* @param range percentage reference for the destination channel
|
|
121
|
+
*/
|
|
122
|
+
function evaluateCalc(body, scope, range) {
|
|
123
|
+
const tokens = lex(body, range);
|
|
124
|
+
let pos = 0;
|
|
125
|
+
const peek = () => tokens[pos];
|
|
126
|
+
const next = () => tokens[pos++];
|
|
127
|
+
function parseExpr() {
|
|
128
|
+
let value = parseTerm();
|
|
129
|
+
for (;;) {
|
|
130
|
+
const tok = peek();
|
|
131
|
+
if (tok && tok.t === 'op' && (tok.v === '+' || tok.v === '-')) {
|
|
132
|
+
next();
|
|
133
|
+
const rhs = parseTerm();
|
|
134
|
+
value = tok.v === '+' ? value + rhs : value - rhs;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function parseTerm() {
|
|
142
|
+
let value = parseFactor();
|
|
143
|
+
for (;;) {
|
|
144
|
+
const tok = peek();
|
|
145
|
+
if (tok && tok.t === 'op' && (tok.v === '*' || tok.v === '/')) {
|
|
146
|
+
next();
|
|
147
|
+
const rhs = parseFactor();
|
|
148
|
+
value = tok.v === '*' ? value * rhs : value / rhs;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
function parseFactor() {
|
|
156
|
+
const tok = next();
|
|
157
|
+
if (!tok) {
|
|
158
|
+
fail('unexpected end of expression', body);
|
|
159
|
+
}
|
|
160
|
+
switch (tok.t) {
|
|
161
|
+
case 'num':
|
|
162
|
+
return tok.v;
|
|
163
|
+
case 'id': {
|
|
164
|
+
// constants and channel keywords
|
|
165
|
+
if (tok.v === 'pi')
|
|
166
|
+
return Math.PI;
|
|
167
|
+
if (tok.v === 'e')
|
|
168
|
+
return Math.E;
|
|
169
|
+
if (tok.v === 'infinity')
|
|
170
|
+
return Infinity;
|
|
171
|
+
if (tok.v === 'nan')
|
|
172
|
+
return NaN;
|
|
173
|
+
if (tok.v === 'none')
|
|
174
|
+
return 0;
|
|
175
|
+
const bound = scope.get(tok.v);
|
|
176
|
+
if (bound === undefined) {
|
|
177
|
+
fail(`unknown identifier "${tok.v}"`, body);
|
|
178
|
+
}
|
|
179
|
+
return bound;
|
|
180
|
+
}
|
|
181
|
+
case 'op':
|
|
182
|
+
if (tok.v === '-')
|
|
183
|
+
return -parseFactor();
|
|
184
|
+
if (tok.v === '+')
|
|
185
|
+
return parseFactor();
|
|
186
|
+
fail(`unexpected "${tok.v}"`, body);
|
|
187
|
+
case 'lparen': {
|
|
188
|
+
const value = parseExpr();
|
|
189
|
+
const close = next();
|
|
190
|
+
if (!close || close.t !== 'rparen') {
|
|
191
|
+
fail('expected ")"', body);
|
|
192
|
+
}
|
|
193
|
+
return value;
|
|
194
|
+
}
|
|
195
|
+
default:
|
|
196
|
+
fail('unexpected token', body);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const result = parseExpr();
|
|
200
|
+
if (pos !== tokens.length) {
|
|
201
|
+
fail('trailing tokens', body);
|
|
202
|
+
}
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=calc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc.js","sour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AM,KAAK,GAAG,IAAI,EAAE,CAAA;gBACpB,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;oBACnC,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAA;gBAC5B,CAAC;gBACD,OAAO,KAAK,CAAA;YACd,CAAC;YACD;gBACE,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAA;QAClC,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,IAAI,GAAG,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAA;IAC/B,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ColorBits } from '../core/bits';
|
|
2
|
+
import type { Tokens } from './tokenizer';
|
|
3
|
+
/**
|
|
4
|
+
* Resolve a color-mix() from its tokenized form.
|
|
5
|
+
* @param tokens tokenized `color-mix(...)`
|
|
6
|
+
* @param parseColor parser for the two color arguments (recursive)
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveColorMix(tokens: Tokens, parseColor: (input: string) => ColorBits): ColorBits;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveColorMix = resolveColorMix;
|
|
4
|
+
const channels_1 = require("../conversion/channels");
|
|
5
|
+
const color_mix_1 = require("../operations/color-mix");
|
|
6
|
+
const PERCENT = 37; // '%'
|
|
7
|
+
function fail(message) {
|
|
8
|
+
throw new Error('color-mix(): ' + message);
|
|
9
|
+
}
|
|
10
|
+
/** Parse one `<color> [<percentage>]` (order-independent) color-mix argument. */
|
|
11
|
+
function parseColorArg(group, parseColor) {
|
|
12
|
+
let colorToken;
|
|
13
|
+
let p;
|
|
14
|
+
for (const token of group) {
|
|
15
|
+
if (token.charCodeAt(token.length - 1) === PERCENT) {
|
|
16
|
+
if (p !== undefined) {
|
|
17
|
+
fail(`unexpected "${token}"`);
|
|
18
|
+
}
|
|
19
|
+
p = parseFloat(token);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
if (colorToken !== undefined) {
|
|
23
|
+
fail(`unexpected "${token}"`);
|
|
24
|
+
}
|
|
25
|
+
colorToken = token;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (colorToken === undefined) {
|
|
29
|
+
fail('missing color');
|
|
30
|
+
}
|
|
31
|
+
return { color: parseColor(colorToken), p };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolve a color-mix() from its tokenized form.
|
|
35
|
+
* @param tokens tokenized `color-mix(...)`
|
|
36
|
+
* @param parseColor parser for the two color arguments (recursive)
|
|
37
|
+
*/
|
|
38
|
+
function resolveColorMix(tokens, parseColor) {
|
|
39
|
+
const groups = [[]];
|
|
40
|
+
for (const token of tokens.tokens) {
|
|
41
|
+
if (token === ',') {
|
|
42
|
+
groups.push([]);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
groups[groups.length - 1].push(token);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (groups.length !== 3) {
|
|
49
|
+
fail('expected "in <space>, <color>, <color>"');
|
|
50
|
+
}
|
|
51
|
+
const inClause = groups[0].map((token) => token.toLowerCase());
|
|
52
|
+
if (inClause[0] !== 'in' || inClause[1] === undefined) {
|
|
53
|
+
fail('expected "in <space>, <color>, <color>"');
|
|
54
|
+
}
|
|
55
|
+
const space = inClause[1];
|
|
56
|
+
let hue;
|
|
57
|
+
if (inClause.length !== 2) {
|
|
58
|
+
const method = inClause[2];
|
|
59
|
+
if (inClause.length !== 4 || inClause[3] !== 'hue' ||
|
|
60
|
+
(method !== 'shorter' && method !== 'longer' && method !== 'increasing' && method !== 'decreasing')) {
|
|
61
|
+
fail(`invalid interpolation: "${groups[0].join(' ')}"`);
|
|
62
|
+
}
|
|
63
|
+
hue = method;
|
|
64
|
+
}
|
|
65
|
+
const arg1 = parseColorArg(groups[1], parseColor);
|
|
66
|
+
const arg2 = parseColorArg(groups[2], parseColor);
|
|
67
|
+
// CSS also allows predefined color() spaces, which have no named model.
|
|
68
|
+
return (0, color_mix_1.colorMix)(arg1.color, arg2.color, { space: (0, channels_1.colorSpaceModel)(space) ?? space, hue, p1: arg1.p, p2: arg2.p });
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=color-mix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-mix.js","sourceRoot":"","sources":["../../src/parsing/color-mix.ts"],"names":[],"mappings":";;AAwCA,0CAoCC;AA3ED,qDAAwD;AACxD,uDAAkD;AAIlD,MAAM,OAAO,GAAG,EAAE,CAAA,CAAC,MAAM;AAEzB,SAAS,IAAI,CAAC,OAAe;IAC3B,MAAM,IAAI,KAAK,CAAC,eAAe,GAAG,OAAO,CAAC,CAAA;AAC5C,CAAC;AAED,iFAAiF;AACjF,SAAS,aAAa,CAAC,KAAe,EAAE,UAAwC;IAC9E,IAAI,UAA8B,CAAA;IAClC,IAAI,CAAqB,CAAA;IACzB,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,OAAO,EAAE,CAAC;YACnD,IAAI,CAAC,KAAK,SAAS,EAAE,CAAC;gBACpB,IAAI,CAAC,eAAe,KAAK,GAAG,CAAC,CAAA;YAC/B,CAAC;YACD,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QACvB,CAAC;aAAM,CAAC;YACN,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,IAAI,CAAC,eAAe,KAAK,GAAG,CAAC,CAAA;YAC/B,CAAC;YACD,UAAU,GAAG,KAAK,CAAA;QACpB,CAAC;IACH,CAAC;IACD,IAAI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AAK;YAC9C,CAAC,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,YAAY,IAAI,MAAM,KAAK,YAAY,CAAC,EACnG,CAAC;YACD,IAAI,CAAC,2BAA2B,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QACzD,CAAC;QACD,GAAG,GAAG,MAAM,CAAA;IACd,CAAC;IAED,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;IACjD,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,CAAA;IAEjD,wEAAwE;IACxE,OAAO,IAAA,oBAAQ,EAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAA,0BAAe,EAAC,KAAK,CAAC,IAAI,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC,CAAA;AAClH,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ColorBits } from '../core/bits';
|
|
2
|
+
export { colorMix } from '../operations/color-mix';
|
|
3
|
+
export type { HueMethod, ColorMixOptions } from '../operations/color-mix';
|
|
4
|
+
export { colorModel, colorSpaceModel } from '../conversion/channels';
|
|
5
|
+
export type { ColorModel } from '../conversion/channels';
|
|
6
|
+
export { resolveNamed, namedColors } from './named-colors';
|
|
7
|
+
/**
|
|
8
|
+
* Resolves a color keyword that has no fixed value — `currentColor` and system
|
|
9
|
+
* colors (e.g. `Canvas`, `ButtonText`). Return ColorBits, a CSS color string, or
|
|
10
|
+
* null if unresolved. In the browser this is typically backed by
|
|
11
|
+
* `getComputedStyle`.
|
|
12
|
+
*/
|
|
13
|
+
export type ColorResolver = (name: string) => ColorBits | string | null;
|
|
14
|
+
export interface ParseCSSOptions {
|
|
15
|
+
resolve?: ColorResolver;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse any CSS Color Module 4/5 color: hex, named colors, rgb()/hsl()/hwb()/
|
|
19
|
+
* lab()/lch()/oklab()/oklch()/color(), their relative `from …` forms, calc()
|
|
20
|
+
* channels, and color-mix(). For `currentColor`/system colors, pass
|
|
21
|
+
* `options.resolve`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseCSS(input: string, options?: ParseCSSOptions): ColorBits;
|