@electrovir/color 0.0.0 → 1.1.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/dist/{color-formats.d.ts → color-class/color-formats.d.ts} +28 -22
- package/dist/{color-formats.js → color-class/color-formats.js} +24 -10
- package/dist/{color.d.ts → color-class/color.d.ts} +6 -6
- package/dist/{color.js → color-class/color.js} +13 -12
- package/dist/contrast/contrast.d.ts +229 -0
- package/dist/contrast/contrast.js +254 -0
- package/dist/elements/vir-all-color-space-sliders.element.d.ts +11 -0
- package/dist/elements/vir-all-color-space-sliders.element.js +52 -0
- package/dist/elements/vir-color-format-sliders.element.d.ts +13 -0
- package/dist/elements/vir-color-format-sliders.element.js +54 -0
- package/dist/elements/vir-color-pair.element.d.ts +23 -0
- package/dist/elements/vir-color-pair.element.js +196 -0
- package/dist/elements/vir-color-slider.element.d.ts +14 -0
- package/dist/elements/vir-color-slider.element.js +101 -0
- package/dist/elements/vir-contrast-indicator.element.d.ts +10 -0
- package/dist/elements/vir-contrast-indicator.element.js +96 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +9 -3
- package/package.json +48 -37
- /package/dist/{color-name-length.d.ts → color-class/color-name-length.d.ts} +0 -0
- /package/dist/{color-name-length.js → color-class/color-name-length.js} +0 -0
|
@@ -28,16 +28,6 @@ export type ColorCoordinateDefinition = {
|
|
|
28
28
|
factor?: number | undefined;
|
|
29
29
|
suffix?: string;
|
|
30
30
|
}>;
|
|
31
|
-
/**
|
|
32
|
-
* A single color format definition.
|
|
33
|
-
*
|
|
34
|
-
* @category Internal
|
|
35
|
-
*/
|
|
36
|
-
export type ColorFormatDefinition<ColorSpace extends string = string> = {
|
|
37
|
-
coords: Record<string, ColorCoordinateDefinition>;
|
|
38
|
-
/** This name for this color to be used in `Colorjs.to()`. Defaults to the color format key. */
|
|
39
|
-
colorSpace: ColorSpace;
|
|
40
|
-
};
|
|
41
31
|
/**
|
|
42
32
|
* All raw supported color formats.
|
|
43
33
|
*
|
|
@@ -184,15 +174,17 @@ export declare const rawColorFormats: {
|
|
|
184
174
|
};
|
|
185
175
|
};
|
|
186
176
|
/**
|
|
187
|
-
* All supported color format names.
|
|
177
|
+
* All supported color format names.
|
|
188
178
|
*
|
|
189
179
|
* @category Internal
|
|
180
|
+
* @enum
|
|
190
181
|
*/
|
|
191
|
-
export declare const ColorFormatName: { [
|
|
182
|
+
export declare const ColorFormatName: { [Key in ColorFormatName]: Key; };
|
|
192
183
|
/**
|
|
193
|
-
* All supported color format names.
|
|
184
|
+
* All supported color format names.
|
|
194
185
|
*
|
|
195
186
|
* @category Internal
|
|
187
|
+
* @enum
|
|
196
188
|
*/
|
|
197
189
|
export type ColorFormatName = keyof typeof rawColorFormats;
|
|
198
190
|
/**
|
|
@@ -210,9 +202,9 @@ export type ColorCoordsByFormat = {
|
|
|
210
202
|
* @category Internal
|
|
211
203
|
*/
|
|
212
204
|
export type ColorFormats = Readonly<{
|
|
213
|
-
[FormatName in ColorFormatName]: ColorFormatDefinition<
|
|
205
|
+
[FormatName in ColorFormatName]: ColorFormatDefinition<Extract<(typeof rawColorFormats)[FormatName], {
|
|
214
206
|
colorSpace: any;
|
|
215
|
-
}>['colorSpace']
|
|
207
|
+
}>['colorSpace'], FormatName>;
|
|
216
208
|
}>;
|
|
217
209
|
/**
|
|
218
210
|
* All supported color formats.
|
|
@@ -221,17 +213,25 @@ export type ColorFormats = Readonly<{
|
|
|
221
213
|
*/
|
|
222
214
|
export declare const colorFormats: ColorFormats;
|
|
223
215
|
/**
|
|
224
|
-
* All
|
|
216
|
+
* All supported color space names.
|
|
225
217
|
*
|
|
226
218
|
* @category Internal
|
|
219
|
+
* @enum
|
|
227
220
|
*/
|
|
228
221
|
export type ColorSpaceName = Values<typeof rawColorFormats>['colorSpace'];
|
|
222
|
+
/**
|
|
223
|
+
* All supported color space names.
|
|
224
|
+
*
|
|
225
|
+
* @category Internal
|
|
226
|
+
* @enum
|
|
227
|
+
*/
|
|
228
|
+
export declare const ColorSpaceName: { [Key in ColorSpaceName]: Key; };
|
|
229
229
|
/**
|
|
230
230
|
* All value types for all supported color formats.
|
|
231
231
|
*
|
|
232
232
|
* @category Internal
|
|
233
233
|
*/
|
|
234
|
-
export type
|
|
234
|
+
export type ColorValue = {
|
|
235
235
|
[FormatName in ColorFormatName]: Record<keyof (typeof rawColorFormats)[FormatName]['coords'], number>;
|
|
236
236
|
};
|
|
237
237
|
/**
|
|
@@ -239,16 +239,22 @@ export type ColorValues = {
|
|
|
239
239
|
*
|
|
240
240
|
* @category Color Format
|
|
241
241
|
*/
|
|
242
|
-
export declare const
|
|
242
|
+
export declare const colorFormatsBySpace: { [ColorSpace in ColorSpaceName]: { [ColorFormat in ColorFormatName]: ColorFormatDefinition<ColorSpace, ColorFormat>; }; };
|
|
243
243
|
/**
|
|
244
|
-
* All
|
|
244
|
+
* All possible coordinate names for all supported color formats in a union.
|
|
245
245
|
*
|
|
246
246
|
* @category Internal
|
|
247
247
|
*/
|
|
248
|
-
export
|
|
248
|
+
export type ColorCoordinateName = keyof UnionToIntersection<Values<typeof rawColorFormats>['coords']>;
|
|
249
249
|
/**
|
|
250
|
-
*
|
|
250
|
+
* A single color format definition.
|
|
251
251
|
*
|
|
252
252
|
* @category Internal
|
|
253
253
|
*/
|
|
254
|
-
export type
|
|
254
|
+
export type ColorFormatDefinition<ColorSpace extends ColorSpaceName = any, ColorFormat extends ColorFormatName = any> = {
|
|
255
|
+
/** Which exact color coordinates exist in here depends on the set color space. */
|
|
256
|
+
coords: Record<ColorCoordsByFormat[ColorFormat], ColorCoordinateDefinition>;
|
|
257
|
+
/** This name for this color to be used in `Colorjs.to()`. Defaults to the color format key. */
|
|
258
|
+
colorSpace: ColorSpace;
|
|
259
|
+
colorFormat: ColorFormat;
|
|
260
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getObjectTypedEntries,
|
|
1
|
+
import { arrayToObject, getObjectTypedEntries, getObjectTypedValues, getOrSet, mapObjectValues, } from '@augment-vir/common';
|
|
2
2
|
/**
|
|
3
3
|
* All raw supported color formats.
|
|
4
4
|
*
|
|
@@ -145,9 +145,10 @@ export const rawColorFormats = {
|
|
|
145
145
|
},
|
|
146
146
|
};
|
|
147
147
|
/**
|
|
148
|
-
* All supported color format names.
|
|
148
|
+
* All supported color format names.
|
|
149
149
|
*
|
|
150
150
|
* @category Internal
|
|
151
|
+
* @enum
|
|
151
152
|
*/
|
|
152
153
|
export const ColorFormatName = mapObjectValues(rawColorFormats, (colorName) => colorName);
|
|
153
154
|
/**
|
|
@@ -155,21 +156,34 @@ export const ColorFormatName = mapObjectValues(rawColorFormats, (colorName) => c
|
|
|
155
156
|
*
|
|
156
157
|
* @category Color Format
|
|
157
158
|
*/
|
|
158
|
-
export const colorFormats = rawColorFormats
|
|
159
|
+
export const colorFormats = mapObjectValues(rawColorFormats, (colorFormatName, colorFormatValue) => {
|
|
160
|
+
return {
|
|
161
|
+
...colorFormatValue,
|
|
162
|
+
colorFormat: colorFormatName,
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* All supported color space names.
|
|
167
|
+
*
|
|
168
|
+
* @category Internal
|
|
169
|
+
* @enum
|
|
170
|
+
*/
|
|
171
|
+
export const ColorSpaceName = arrayToObject(getObjectTypedValues(rawColorFormats), (format) => {
|
|
172
|
+
return {
|
|
173
|
+
key: format.colorSpace,
|
|
174
|
+
value: format.colorSpace,
|
|
175
|
+
};
|
|
176
|
+
}, {
|
|
177
|
+
useRequired: true,
|
|
178
|
+
});
|
|
159
179
|
/**
|
|
160
180
|
* All color formats grouped by their color space.
|
|
161
181
|
*
|
|
162
182
|
* @category Color Format
|
|
163
183
|
*/
|
|
164
|
-
export const
|
|
184
|
+
export const colorFormatsBySpace = getObjectTypedEntries(colorFormats).reduce((accum, [colorFormatName, colorFormatDefinition,]) => {
|
|
165
185
|
getOrSet(accum, colorFormatDefinition.colorSpace, () => {
|
|
166
186
|
return {};
|
|
167
187
|
})[colorFormatName] = colorFormatDefinition;
|
|
168
188
|
return accum;
|
|
169
189
|
}, {});
|
|
170
|
-
/**
|
|
171
|
-
* All color format names in an array.
|
|
172
|
-
*
|
|
173
|
-
* @category Internal
|
|
174
|
-
*/
|
|
175
|
-
export const colorFormatNames = getObjectTypedKeys(colorFormats);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
2
|
import { type RequireExactlyOne } from 'type-fest';
|
|
3
|
-
import {
|
|
3
|
+
import { ColorFormatName, type ColorCoordsByFormat, type ColorValue, type HexColor } from './color-formats.js';
|
|
4
4
|
/**
|
|
5
5
|
* An update to an existing {@link Color} instance. Used in {@link Color.set}.
|
|
6
6
|
*
|
|
@@ -14,11 +14,11 @@ export type ColorUpdate = RequireExactlyOne<{
|
|
|
14
14
|
}>;
|
|
15
15
|
/**
|
|
16
16
|
* The values of all supported color formats for a given {@link Color} instance. Accessed via
|
|
17
|
-
*
|
|
17
|
+
* `Color.allColors`.
|
|
18
18
|
*
|
|
19
19
|
* @category Internal
|
|
20
20
|
*/
|
|
21
|
-
export type AllColorsValues =
|
|
21
|
+
export type AllColorsValues = ColorValue & {
|
|
22
22
|
hex: HexColor;
|
|
23
23
|
names: string[];
|
|
24
24
|
};
|
|
@@ -35,6 +35,9 @@ export type AllColorsValues = ColorValues & {
|
|
|
35
35
|
*/
|
|
36
36
|
export declare class Color {
|
|
37
37
|
#private;
|
|
38
|
+
constructor(
|
|
39
|
+
/** Any valid CSS color string or an object of color coordinate values. */
|
|
40
|
+
initValue: string | Readonly<ColorUpdate>);
|
|
38
41
|
/**
|
|
39
42
|
* Create a new {@link Color} instance by parsing the output of another instance's
|
|
40
43
|
* {@link Color.serialize} method.
|
|
@@ -80,9 +83,6 @@ export declare class Color {
|
|
|
80
83
|
h: number;
|
|
81
84
|
};
|
|
82
85
|
};
|
|
83
|
-
constructor(
|
|
84
|
-
/** Any valid CSS color string or an object of color coordinate values. */
|
|
85
|
-
initValue: string | Readonly<ColorUpdate>);
|
|
86
86
|
/** Create a new {@link Color} instance that matches this one exactly. */
|
|
87
87
|
clone(): Color;
|
|
88
88
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { assert, assertWrap, check } from '@augment-vir/assert';
|
|
2
|
-
import { copyThroughJson, filterMap, getObjectTypedEntries, joinWithFinalConjunction, mapObjectValues, round, } from '@augment-vir/common';
|
|
2
|
+
import { copyThroughJson, filterMap, getEnumValues, getObjectTypedEntries, getObjectTypedKeys, joinWithFinalConjunction, mapObjectValues, round, } from '@augment-vir/common';
|
|
3
3
|
import colorNames from 'color-name';
|
|
4
4
|
import { clampGamut, converter, formatHex, parse } from 'culori';
|
|
5
|
-
import {
|
|
5
|
+
import { ColorFormatName, colorFormats, } from './color-formats.js';
|
|
6
6
|
import { maxColorNameLength } from './color-name-length.js';
|
|
7
7
|
/**
|
|
8
8
|
* A `Color` class with state and the following features:
|
|
@@ -16,6 +16,11 @@ import { maxColorNameLength } from './color-name-length.js';
|
|
|
16
16
|
* @category Color
|
|
17
17
|
*/
|
|
18
18
|
export class Color {
|
|
19
|
+
constructor(
|
|
20
|
+
/** Any valid CSS color string or an object of color coordinate values. */
|
|
21
|
+
initValue) {
|
|
22
|
+
this.set(initValue);
|
|
23
|
+
}
|
|
19
24
|
/**
|
|
20
25
|
* Create a new {@link Color} instance by parsing the output of another instance's
|
|
21
26
|
* {@link Color.serialize} method.
|
|
@@ -69,11 +74,6 @@ export class Color {
|
|
|
69
74
|
h: 0,
|
|
70
75
|
},
|
|
71
76
|
};
|
|
72
|
-
constructor(
|
|
73
|
-
/** Any valid CSS color string or an object of color coordinate values. */
|
|
74
|
-
initValue) {
|
|
75
|
-
this.set(initValue);
|
|
76
|
-
}
|
|
77
77
|
/** Create a new {@link Color} instance that matches this one exactly. */
|
|
78
78
|
clone() {
|
|
79
79
|
return Color.deserialize(this.serialize());
|
|
@@ -109,7 +109,7 @@ export class Color {
|
|
|
109
109
|
const colorFormatDefinition = colorFormats[colorFormatName];
|
|
110
110
|
const orderedColorCoords = Object.values(mapObjectValues(colorFormatDefinition.coords, (coordName) => {
|
|
111
111
|
const coordValue = colorValues[coordName];
|
|
112
|
-
const coordDefinition = assertWrap.
|
|
112
|
+
const coordDefinition = colorFormatDefinition.coords[assertWrap.isKeyOf(coordName, colorFormatDefinition.coords)];
|
|
113
113
|
const rawCoordValue = coordValue != undefined &&
|
|
114
114
|
coordValue >= coordDefinition.min &&
|
|
115
115
|
coordValue <= coordDefinition.max
|
|
@@ -125,7 +125,7 @@ export class Color {
|
|
|
125
125
|
* internal color object.
|
|
126
126
|
*/
|
|
127
127
|
pullFromInternalColor() {
|
|
128
|
-
|
|
128
|
+
getEnumValues(ColorFormatName).forEach((colorFormatName) => {
|
|
129
129
|
const colorFormatDefinition = colorFormats[colorFormatName];
|
|
130
130
|
const originalColorDefinition = check.isKeyOf(this.#internalColor.mode, colorFormats)
|
|
131
131
|
? colorFormats[this.#internalColor.mode]
|
|
@@ -137,11 +137,12 @@ export class Color {
|
|
|
137
137
|
if (!converted) {
|
|
138
138
|
assert.never(`Failed to convert color '${JSON.stringify(this.#internalColor)}' to '${colorFormatName}'.`);
|
|
139
139
|
}
|
|
140
|
-
|
|
140
|
+
getObjectTypedKeys(this[colorFormatName]).forEach((coordName) => {
|
|
141
141
|
const coordValue = converted[coordName];
|
|
142
|
+
const coordinateDefinition = colorFormatDefinition.coords[assertWrap.isKeyOf(coordName, colorFormatDefinition.coords)];
|
|
142
143
|
if (coordValue != undefined) {
|
|
143
|
-
this._allColors[colorFormatName][coordName] = round((coordValue || 0) * (
|
|
144
|
-
digits:
|
|
144
|
+
this._allColors[colorFormatName][coordName] = round((coordValue || 0) * (coordinateDefinition.factor || 1), {
|
|
145
|
+
digits: coordinateDefinition.digits || 0,
|
|
145
146
|
});
|
|
146
147
|
}
|
|
147
148
|
});
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { type ArrayElement, type ExtractKeysWithMatchingValues, type Values } from '@augment-vir/common';
|
|
2
|
+
/**
|
|
3
|
+
* All font weights that font sizes are calculated for. Used in {@link FontSizes} and
|
|
4
|
+
* {@link calculateFontSizes}.
|
|
5
|
+
*
|
|
6
|
+
* @category Internal
|
|
7
|
+
*/
|
|
8
|
+
export type FontWeight = 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900;
|
|
9
|
+
/**
|
|
10
|
+
* All considered font weights in {@link FontWeight} mapped by their weight name.
|
|
11
|
+
*
|
|
12
|
+
* @category Internal
|
|
13
|
+
*/
|
|
14
|
+
export declare const fontWeightByName: {
|
|
15
|
+
readonly Thin: 100;
|
|
16
|
+
readonly ExtraLight: 200;
|
|
17
|
+
readonly Light: 300;
|
|
18
|
+
readonly Normal: 400;
|
|
19
|
+
readonly Medium: 500;
|
|
20
|
+
readonly SemiBold: 600;
|
|
21
|
+
readonly Bold: 700;
|
|
22
|
+
readonly ExtraBold: 800;
|
|
23
|
+
readonly Heavy: 900;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* All font weight names from {@link fontWeightByName}.
|
|
27
|
+
*
|
|
28
|
+
* @category Internal
|
|
29
|
+
*/
|
|
30
|
+
export type FontWeightName = keyof typeof fontWeightByName;
|
|
31
|
+
/**
|
|
32
|
+
* All font weight names from {@link fontWeightByName}.
|
|
33
|
+
*
|
|
34
|
+
* @category Internal
|
|
35
|
+
*/
|
|
36
|
+
export declare const FontWeightName: { [Key in FontWeightName]: Key; };
|
|
37
|
+
/**
|
|
38
|
+
* All considered font weights in {@link FontWeight} mapped to their weight name from
|
|
39
|
+
* {@link fontWeightByName}.
|
|
40
|
+
*
|
|
41
|
+
* @category Internal
|
|
42
|
+
*/
|
|
43
|
+
export declare const fontWeightToName: { [Weight in Values<typeof fontWeightByName>]: ExtractKeysWithMatchingValues<typeof fontWeightByName, Weight>; };
|
|
44
|
+
/**
|
|
45
|
+
* A mapping of font weights to font sizes. Used in {@link calculateFontSizes}.
|
|
46
|
+
*
|
|
47
|
+
* @category Internal
|
|
48
|
+
*/
|
|
49
|
+
export type FontSizes = Record<FontWeight, number>;
|
|
50
|
+
/**
|
|
51
|
+
* Contrast calculations produced by {@link calculateContrast}.
|
|
52
|
+
*
|
|
53
|
+
* @category Internal
|
|
54
|
+
*/
|
|
55
|
+
export type CalculatedContrast = {
|
|
56
|
+
/** The raw APCA LC contrast value. */
|
|
57
|
+
contrast: number;
|
|
58
|
+
/** The minimum font size for each font weight for the current `contrast` value. */
|
|
59
|
+
fontSizes: FontSizes;
|
|
60
|
+
/** The contrast level for the current `contrast` value. */
|
|
61
|
+
contrastLevel: ContrastLevel;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The value of each color may be any valid CSS color string.
|
|
65
|
+
*
|
|
66
|
+
* @category Internal
|
|
67
|
+
*/
|
|
68
|
+
export type CalculateContrastParams = {
|
|
69
|
+
foreground: string;
|
|
70
|
+
background: string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Calculate contrast for the given color combination.
|
|
74
|
+
*
|
|
75
|
+
* @category Internal
|
|
76
|
+
*/
|
|
77
|
+
export declare function calculateContrast({ background, foreground, }: Readonly<CalculateContrastParams>): CalculatedContrast;
|
|
78
|
+
/** @category Internal */
|
|
79
|
+
export declare function findClosestColor(baseColor: string, possibleColors: ReadonlyArray<string>): string;
|
|
80
|
+
/**
|
|
81
|
+
* Find a color from an array that matches the desired contrast level.
|
|
82
|
+
*
|
|
83
|
+
* @category Internal
|
|
84
|
+
* @returns `undefined` if no color match is found.
|
|
85
|
+
*/
|
|
86
|
+
export declare function findColorAtContrastLevel(colors: Readonly<{
|
|
87
|
+
foreground: string;
|
|
88
|
+
background: string[];
|
|
89
|
+
} | {
|
|
90
|
+
foreground: string[];
|
|
91
|
+
background: string;
|
|
92
|
+
}>, desiredContrastLevel: ContrastLevelName): string | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Calculated needed font sizes for each font weight for the given color contrast.
|
|
95
|
+
*
|
|
96
|
+
* @category Internal
|
|
97
|
+
*/
|
|
98
|
+
export declare function calculateFontSizes(contrast: number): FontSizes;
|
|
99
|
+
/**
|
|
100
|
+
* Finds the color contrast level for the given contrast.
|
|
101
|
+
*
|
|
102
|
+
* @category Internal
|
|
103
|
+
*/
|
|
104
|
+
export declare function determineContrastLevel(contrast: number): ContrastLevel;
|
|
105
|
+
/**
|
|
106
|
+
* Names for each {@link ContrastLevel}.
|
|
107
|
+
*
|
|
108
|
+
* @category Internal
|
|
109
|
+
*/
|
|
110
|
+
export declare enum ContrastLevelName {
|
|
111
|
+
SmallBodyText = "small-body",
|
|
112
|
+
BodyText = "body",
|
|
113
|
+
NonBodyText = "non-body",
|
|
114
|
+
Header = "header",
|
|
115
|
+
Placeholder = "placeholder",
|
|
116
|
+
Decoration = "decoration",
|
|
117
|
+
Invisible = "invisible"
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* User-facing labels for {@link ContrastLevelName}.
|
|
121
|
+
*
|
|
122
|
+
* @category Internal
|
|
123
|
+
*/
|
|
124
|
+
export declare const contrastLevelLabel: Record<ContrastLevelName, string>;
|
|
125
|
+
/**
|
|
126
|
+
* All {@link ContrastLevelName} values in order from highest contrast to lowest.
|
|
127
|
+
*
|
|
128
|
+
* @category Internal
|
|
129
|
+
*/
|
|
130
|
+
export declare const orderedContrastLevelNames: readonly [ContrastLevelName.SmallBodyText, ContrastLevelName.BodyText, ContrastLevelName.NonBodyText, ContrastLevelName.Header, ContrastLevelName.Placeholder, ContrastLevelName.Decoration, ContrastLevelName.Invisible];
|
|
131
|
+
/**
|
|
132
|
+
* Color contrast level details.
|
|
133
|
+
*
|
|
134
|
+
* @category Internal
|
|
135
|
+
*/
|
|
136
|
+
export type ContrastLevel = {
|
|
137
|
+
/** The minimum contrast level threshold for this contrast level. */
|
|
138
|
+
min: number;
|
|
139
|
+
/** The name corresponding to the smallest text or non-text item that this can be used for. */
|
|
140
|
+
name: ContrastLevelName;
|
|
141
|
+
/** Short description for this contrast level. */
|
|
142
|
+
description: string;
|
|
143
|
+
/** Name from the APCA guidelines (confusing). */
|
|
144
|
+
apcaName: string;
|
|
145
|
+
/** Description from the APCA guidelines (verbose). */
|
|
146
|
+
apcaDescription: string;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* All color contrast levels corresponding to APCA bronze guidelines.
|
|
150
|
+
*
|
|
151
|
+
* @category Internal
|
|
152
|
+
*/
|
|
153
|
+
export declare const contrastLevels: readonly [{
|
|
154
|
+
readonly min: 90;
|
|
155
|
+
readonly name: ContrastLevelName.SmallBodyText;
|
|
156
|
+
readonly description: "Perfect for all sizes of text, even small body text.";
|
|
157
|
+
readonly apcaName: "small body text only";
|
|
158
|
+
readonly apcaDescription: "Preferred level for fluent text and columns of body text with a font no smaller than 18px/weight 300 or 14px/weight 400 (normal), or non-body text with a font no smaller than 12px. Also a recommended minimum for extremely thin fonts with a minimum of 24px at weight 200. Lc 90 is a suggested maximum for very large and bold fonts (greater than 36px bold), and large areas of color.";
|
|
159
|
+
}, {
|
|
160
|
+
readonly min: 75;
|
|
161
|
+
readonly name: ContrastLevelName.BodyText;
|
|
162
|
+
readonly description: "Good for regular body text and anything larger.";
|
|
163
|
+
readonly apcaName: "body text okay";
|
|
164
|
+
readonly apcaDescription: "The minimum level for columns of body text with a font no smaller than 24px/300 weight, 18px/400, 16px/500 and 14px/700. This level may be used with non-body text with a font no smaller than 15px/400. Also, Lc 75 should be considered a minimum for larger for any larger text where readability is important.";
|
|
165
|
+
}, {
|
|
166
|
+
readonly min: 60;
|
|
167
|
+
readonly name: ContrastLevelName.NonBodyText;
|
|
168
|
+
readonly description: "Good for legible non-body text and anything larger.";
|
|
169
|
+
readonly apcaName: "fluent text only";
|
|
170
|
+
readonly apcaDescription: "The minimum level recommended for content text that is not body, column, or block text. In other words, text you want people to read. The minimums: no smaller than 48px/200, 36px/300, 24px normal weight (400), 21px/500, 18px/600, 16px/700 (bold). These values based on the reference font Helvetica. To use these sizes as body text, add Lc 15 to the minimum contrast.";
|
|
171
|
+
}, {
|
|
172
|
+
readonly min: 45;
|
|
173
|
+
readonly name: ContrastLevelName.Header;
|
|
174
|
+
readonly description: "Okay for large or headline text.";
|
|
175
|
+
readonly apcaName: "large & sub-fluent text";
|
|
176
|
+
readonly apcaDescription: "The minimum for larger, heavier text (36px normal weight or 24px bold) such as headlines, and large text that should be fluently readable but is not body text. This is also the minimum for pictograms with fine details, or smaller outline icons, , no less than 4px in its smallest dimension.";
|
|
177
|
+
}, {
|
|
178
|
+
readonly min: 30;
|
|
179
|
+
readonly name: ContrastLevelName.Placeholder;
|
|
180
|
+
readonly description: "Okay for disabled or placeholder text, copyright lines, icons, or non-text elements.";
|
|
181
|
+
readonly apcaName: "spot & non text only";
|
|
182
|
+
readonly apcaDescription: "The absolute minimum for any text not listed above, which means non-content text considered as \"spot readable\". This includes placeholder text and disabled element text, and some non-content like a copyright bug. This is also the minimum for large/solid semantic & understandable non-text elements such as \"mostly solid\" icons or pictograms, no less than 10px in its smallest dimension.";
|
|
183
|
+
}, {
|
|
184
|
+
readonly min: 15;
|
|
185
|
+
readonly name: ContrastLevelName.Decoration;
|
|
186
|
+
readonly description: "Only okay for decorations like graphics, borders, dividers, etc. Do not use for any text.";
|
|
187
|
+
readonly apcaName: "no text usage";
|
|
188
|
+
readonly apcaDescription: "The absolute minimum for any non-text that needs to be discernible and differentiable, but does not apply to semantic non-text such as icons, and is no less than 15px in its smallest dimension. This may include dividers, and in some cases large buttons or thick focus visible outlines, but does not include fine details which have a higher minimum. Designers should treat anything below this level as invisible, as it will not be visible for many users. This minimum level should be avoided for any items important to the use, understanding, or interaction of the site.";
|
|
189
|
+
}, {
|
|
190
|
+
readonly min: 0;
|
|
191
|
+
readonly name: ContrastLevelName.Invisible;
|
|
192
|
+
readonly description: "Effectively invisible for users.";
|
|
193
|
+
readonly apcaName: "invisible";
|
|
194
|
+
readonly apcaDescription: "This should be treated as invisible.";
|
|
195
|
+
}];
|
|
196
|
+
/**
|
|
197
|
+
* Type for {@link contrastLevelMinMap}.
|
|
198
|
+
*
|
|
199
|
+
* @category Internal
|
|
200
|
+
*/
|
|
201
|
+
export type ContrastLevelMinMap = {
|
|
202
|
+
[Min in ArrayElement<typeof contrastLevels>['min']]: Extract<ArrayElement<typeof contrastLevels>, {
|
|
203
|
+
min: Min;
|
|
204
|
+
}>;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* A mapping of all color contrast levels mins to their contrast levels. Generated from
|
|
208
|
+
* {@link contrastLevels}.
|
|
209
|
+
*
|
|
210
|
+
* @category Internal
|
|
211
|
+
*/
|
|
212
|
+
export declare const contrastLevelMinMap: ContrastLevelMinMap;
|
|
213
|
+
/**
|
|
214
|
+
* Type for {@link contrastLevelMinMap}.
|
|
215
|
+
*
|
|
216
|
+
* @category Internal
|
|
217
|
+
*/
|
|
218
|
+
export type ContrastLevelNameMap = {
|
|
219
|
+
[Name in ArrayElement<typeof contrastLevels>['name']]: Extract<ArrayElement<typeof contrastLevels>, {
|
|
220
|
+
name: Name;
|
|
221
|
+
}>;
|
|
222
|
+
};
|
|
223
|
+
/**
|
|
224
|
+
* A mapping of all color contrast levels mins to their contrast levels. Generated from
|
|
225
|
+
* {@link contrastLevels}.
|
|
226
|
+
*
|
|
227
|
+
* @category Internal
|
|
228
|
+
*/
|
|
229
|
+
export declare const contrastLevelNameMap: ContrastLevelNameMap;
|