theme-vir 28.15.2 → 28.15.4
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/build-color-theme.d.ts +1 -1
- package/dist/color/build-color-theme.js +1 -1
- package/dist/color/color-palette-book-pages.js +4 -5
- package/dist/color/color-theme-book-pages.js +5 -5
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -3
- package/package.json +2 -1
- package/dist/color/contrast.d.ts +0 -230
- package/dist/color/contrast.js +0 -254
- package/dist/color/elements/theme-vir-color-example.element.d.ts +0 -17
- package/dist/color/elements/theme-vir-color-example.element.js +0 -195
- package/dist/color/elements/theme-vir-contrast-indicator.element.d.ts +0 -10
- package/dist/color/elements/theme-vir-contrast-indicator.element.js +0 -95
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type PartialWithUndefined, type RequiredAndNotNull } from '@augment-vir/common';
|
|
2
|
+
import { ContrastLevelName } from '@electrovir/color';
|
|
2
3
|
import { type CssVarDefinitions, type SingleCssVarDefinition } from 'lit-css-vars';
|
|
3
4
|
import { type NoRefColorInit } from './color-theme.js';
|
|
4
|
-
import { ContrastLevelName } from './contrast.js';
|
|
5
5
|
/** @category Internal */
|
|
6
6
|
export type ColorPaletteVars = CssVarDefinitions<Record<`${string}-${string}-${number}`, any>>;
|
|
7
7
|
/** @category Internal */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assert, assertWrap, check } from '@augment-vir/assert';
|
|
2
2
|
import { crossProduct, filterMap, getOrSet, log, mapObjectValues, removeDuplicates, stringify, } from '@augment-vir/common';
|
|
3
|
+
import { ContrastLevelName, contrastLevelLabel, findClosestColor, findColorAtContrastLevel, } from '@electrovir/color';
|
|
3
4
|
import { defineColorTheme, noRefColorInitToString, } from './color-theme.js';
|
|
4
|
-
import { contrastLevelLabel, ContrastLevelName, findClosestColor, findColorAtContrastLevel, } from './contrast.js';
|
|
5
5
|
/**
|
|
6
6
|
* Black and white color values.
|
|
7
7
|
*
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
|
+
import { VirColorPair } from '@electrovir/color';
|
|
2
3
|
import { defineBookPage } from 'element-book';
|
|
3
4
|
import { css, html, unsafeCSS } from 'element-vir';
|
|
4
|
-
import { noNativeSpacing } from 'vira
|
|
5
|
-
import { viraColorPalette } from 'vira/dist/styles/vira-color-palette.js';
|
|
5
|
+
import { noNativeSpacing, viraColorPalette } from 'vira';
|
|
6
6
|
import { buildLowLevelColorTheme, groupColors, } from './build-color-theme.js';
|
|
7
7
|
import { createColorThemeBookPages } from './color-theme-book-pages.js';
|
|
8
|
-
import { ThemeVirColorExample } from './elements/theme-vir-color-example.element.js';
|
|
9
8
|
const blackWhiteCells = [
|
|
10
9
|
{
|
|
11
10
|
title: 'Black',
|
|
@@ -162,7 +161,7 @@ export function createColorPaletteBookPages({ colors, parent, title, includeCont
|
|
|
162
161
|
return html `
|
|
163
162
|
<td>
|
|
164
163
|
<p class="darkness-level">${color.suffix}</p>
|
|
165
|
-
<${
|
|
164
|
+
<${VirColorPair.assign({
|
|
166
165
|
color: {
|
|
167
166
|
background: cell.background || color.definition,
|
|
168
167
|
foreground: cell.foreground || color.definition,
|
|
@@ -171,7 +170,7 @@ export function createColorPaletteBookPages({ colors, parent, title, includeCont
|
|
|
171
170
|
showVarNames: false,
|
|
172
171
|
showContrast: true,
|
|
173
172
|
fontWeight: cell.fontWeight,
|
|
174
|
-
})}></${
|
|
173
|
+
})}></${VirColorPair}>
|
|
175
174
|
</td>
|
|
176
175
|
`;
|
|
177
176
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { check } from '@augment-vir/assert';
|
|
2
2
|
import { groupArrayBy } from '@augment-vir/common';
|
|
3
|
+
import { VirColorPair } from '@electrovir/color';
|
|
3
4
|
import { BookPageControlType, defineBookPage, definePageControl, } from 'element-book';
|
|
4
5
|
import { css, html, listen, nothing } from 'element-vir';
|
|
5
6
|
import { generateThemeCode } from './color-theme.js';
|
|
6
|
-
import { ThemeVirColorExample } from './elements/theme-vir-color-example.element.js';
|
|
7
7
|
/**
|
|
8
8
|
* Create multiple element-book pages to showcase a theme its overrides (if any).
|
|
9
9
|
*
|
|
@@ -36,24 +36,24 @@ export function createColorThemeBookPages({ parent, title, theme, hideInverseCol
|
|
|
36
36
|
throw new Error(`No theme color found by name '${themeColorName}'`);
|
|
37
37
|
}
|
|
38
38
|
const normalTemplate = html `
|
|
39
|
-
<${
|
|
39
|
+
<${VirColorPair.assign({
|
|
40
40
|
color: themeColor,
|
|
41
41
|
showVarValues: true,
|
|
42
42
|
showVarNames: controls['Show Var Names'],
|
|
43
43
|
showContrast: controls['Show Contrast Tips'],
|
|
44
44
|
fontWeight: 400,
|
|
45
|
-
})}></${
|
|
45
|
+
})}></${VirColorPair}>
|
|
46
46
|
`;
|
|
47
47
|
const inverseColor = hideInverseColors ? undefined : inverseThemeColor;
|
|
48
48
|
const inverseTemplate = inverseColor
|
|
49
49
|
? html `
|
|
50
|
-
<${
|
|
50
|
+
<${VirColorPair.assign({
|
|
51
51
|
color: inverseColor,
|
|
52
52
|
showVarValues: false,
|
|
53
53
|
showVarNames: controls['Show Var Names'],
|
|
54
54
|
showContrast: controls['Show Contrast Tips'],
|
|
55
55
|
fontWeight: 400,
|
|
56
|
-
})}></${
|
|
56
|
+
})}></${VirColorPair}>
|
|
57
57
|
`
|
|
58
58
|
: nothing;
|
|
59
59
|
return html `
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,3 @@ export * from './color/color-palette-book-pages.js';
|
|
|
4
4
|
export * from './color/color-theme-book-pages.js';
|
|
5
5
|
export * from './color/color-theme-override.js';
|
|
6
6
|
export * from './color/color-theme.js';
|
|
7
|
-
export * from './color/contrast.js';
|
|
8
|
-
export * from './color/elements/theme-vir-color-example.element.js';
|
|
9
|
-
export * from './color/elements/theme-vir-contrast-indicator.element.js';
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,3 @@ export * from './color/color-palette-book-pages.js';
|
|
|
4
4
|
export * from './color/color-theme-book-pages.js';
|
|
5
5
|
export * from './color/color-theme-override.js';
|
|
6
6
|
export * from './color/color-theme.js';
|
|
7
|
-
export * from './color/contrast.js';
|
|
8
|
-
export * from './color/elements/theme-vir-color-example.element.js';
|
|
9
|
-
export * from './color/elements/theme-vir-contrast-indicator.element.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theme-vir",
|
|
3
|
-
"version": "28.15.
|
|
3
|
+
"version": "28.15.4",
|
|
4
4
|
"description": "Create an entire web theme.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"design",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@augment-vir/assert": "^31.57.3",
|
|
46
46
|
"@augment-vir/common": "^31.57.3",
|
|
47
|
+
"@electrovir/color": "^1.5.3",
|
|
47
48
|
"apca-w3": "^0.1.9",
|
|
48
49
|
"lit-css-vars": "^3.0.11",
|
|
49
50
|
"type-fest": "^5.3.1"
|
package/dist/color/contrast.d.ts
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
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
|
-
* A color pair of foreground and background colors. The value of each (a string) may be any valid
|
|
65
|
-
* CSS color string.
|
|
66
|
-
*
|
|
67
|
-
* @category Internal
|
|
68
|
-
*/
|
|
69
|
-
export type ColorPair = {
|
|
70
|
-
foreground: string;
|
|
71
|
-
background: string;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* Calculate contrast for the given color combination.
|
|
75
|
-
*
|
|
76
|
-
* @category Internal
|
|
77
|
-
*/
|
|
78
|
-
export declare function calculateContrast({ background, foreground, }: Readonly<ColorPair>): CalculatedContrast;
|
|
79
|
-
/** @category Internal */
|
|
80
|
-
export declare function findClosestColor(baseColor: string, possibleColors: ReadonlyArray<string>): string;
|
|
81
|
-
/**
|
|
82
|
-
* Find a color from an array that matches the desired contrast level.
|
|
83
|
-
*
|
|
84
|
-
* @category Internal
|
|
85
|
-
* @returns `undefined` if no color match is found.
|
|
86
|
-
*/
|
|
87
|
-
export declare function findColorAtContrastLevel(colors: Readonly<{
|
|
88
|
-
foreground: string;
|
|
89
|
-
background: string[];
|
|
90
|
-
} | {
|
|
91
|
-
foreground: string[];
|
|
92
|
-
background: string;
|
|
93
|
-
}>, desiredContrastLevel: ContrastLevelName): string | undefined;
|
|
94
|
-
/**
|
|
95
|
-
* Calculated needed font sizes for each font weight for the given color contrast.
|
|
96
|
-
*
|
|
97
|
-
* @category Internal
|
|
98
|
-
*/
|
|
99
|
-
export declare function calculateFontSizes(contrast: number): FontSizes;
|
|
100
|
-
/**
|
|
101
|
-
* Finds the color contrast level for the given contrast.
|
|
102
|
-
*
|
|
103
|
-
* @category Internal
|
|
104
|
-
*/
|
|
105
|
-
export declare function determineContrastLevel(contrast: number): ContrastLevel;
|
|
106
|
-
/**
|
|
107
|
-
* Names for each {@link ContrastLevel}.
|
|
108
|
-
*
|
|
109
|
-
* @category Internal
|
|
110
|
-
*/
|
|
111
|
-
export declare enum ContrastLevelName {
|
|
112
|
-
SmallBodyText = "small-body",
|
|
113
|
-
BodyText = "body",
|
|
114
|
-
NonBodyText = "non-body",
|
|
115
|
-
Header = "header",
|
|
116
|
-
Placeholder = "placeholder",
|
|
117
|
-
Decoration = "decoration",
|
|
118
|
-
Invisible = "invisible"
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* User-facing labels for {@link ContrastLevelName}.
|
|
122
|
-
*
|
|
123
|
-
* @category Internal
|
|
124
|
-
*/
|
|
125
|
-
export declare const contrastLevelLabel: Record<ContrastLevelName, string>;
|
|
126
|
-
/**
|
|
127
|
-
* All {@link ContrastLevelName} values in order from highest contrast to lowest.
|
|
128
|
-
*
|
|
129
|
-
* @category Internal
|
|
130
|
-
*/
|
|
131
|
-
export declare const orderedContrastLevelNames: readonly [ContrastLevelName.SmallBodyText, ContrastLevelName.BodyText, ContrastLevelName.NonBodyText, ContrastLevelName.Header, ContrastLevelName.Placeholder, ContrastLevelName.Decoration, ContrastLevelName.Invisible];
|
|
132
|
-
/**
|
|
133
|
-
* Color contrast level details.
|
|
134
|
-
*
|
|
135
|
-
* @category Internal
|
|
136
|
-
*/
|
|
137
|
-
export type ContrastLevel = {
|
|
138
|
-
/** The minimum contrast level threshold for this contrast level. */
|
|
139
|
-
min: number;
|
|
140
|
-
/** The name corresponding to the smallest text or non-text item that this can be used for. */
|
|
141
|
-
name: ContrastLevelName;
|
|
142
|
-
/** Short description for this contrast level. */
|
|
143
|
-
description: string;
|
|
144
|
-
/** Name from the APCA guidelines (confusing). */
|
|
145
|
-
apcaName: string;
|
|
146
|
-
/** Description from the APCA guidelines (verbose). */
|
|
147
|
-
apcaDescription: string;
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* All color contrast levels corresponding to APCA bronze guidelines.
|
|
151
|
-
*
|
|
152
|
-
* @category Internal
|
|
153
|
-
*/
|
|
154
|
-
export declare const contrastLevels: readonly [{
|
|
155
|
-
readonly min: 90;
|
|
156
|
-
readonly name: ContrastLevelName.SmallBodyText;
|
|
157
|
-
readonly description: "Perfect for all sizes of text, even small body text.";
|
|
158
|
-
readonly apcaName: "small body text only";
|
|
159
|
-
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.";
|
|
160
|
-
}, {
|
|
161
|
-
readonly min: 75;
|
|
162
|
-
readonly name: ContrastLevelName.BodyText;
|
|
163
|
-
readonly description: "Good for regular body text and anything larger.";
|
|
164
|
-
readonly apcaName: "body text okay";
|
|
165
|
-
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.";
|
|
166
|
-
}, {
|
|
167
|
-
readonly min: 60;
|
|
168
|
-
readonly name: ContrastLevelName.NonBodyText;
|
|
169
|
-
readonly description: "Good for legible non-body text and anything larger.";
|
|
170
|
-
readonly apcaName: "fluent text only";
|
|
171
|
-
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.";
|
|
172
|
-
}, {
|
|
173
|
-
readonly min: 45;
|
|
174
|
-
readonly name: ContrastLevelName.Header;
|
|
175
|
-
readonly description: "Okay for large or headline text.";
|
|
176
|
-
readonly apcaName: "large & sub-fluent text";
|
|
177
|
-
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.";
|
|
178
|
-
}, {
|
|
179
|
-
readonly min: 30;
|
|
180
|
-
readonly name: ContrastLevelName.Placeholder;
|
|
181
|
-
readonly description: "Okay for disabled or placeholder text, copyright lines, icons, or non-text elements.";
|
|
182
|
-
readonly apcaName: "spot & non text only";
|
|
183
|
-
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.";
|
|
184
|
-
}, {
|
|
185
|
-
readonly min: 15;
|
|
186
|
-
readonly name: ContrastLevelName.Decoration;
|
|
187
|
-
readonly description: "Only okay for decorations like graphics, borders, dividers, etc. Do not use for any text.";
|
|
188
|
-
readonly apcaName: "no text usage";
|
|
189
|
-
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.";
|
|
190
|
-
}, {
|
|
191
|
-
readonly min: 0;
|
|
192
|
-
readonly name: ContrastLevelName.Invisible;
|
|
193
|
-
readonly description: "Effectively invisible for users.";
|
|
194
|
-
readonly apcaName: "invisible";
|
|
195
|
-
readonly apcaDescription: "This should be treated as invisible.";
|
|
196
|
-
}];
|
|
197
|
-
/**
|
|
198
|
-
* Type for {@link contrastLevelMinMap}.
|
|
199
|
-
*
|
|
200
|
-
* @category Internal
|
|
201
|
-
*/
|
|
202
|
-
export type ContrastLevelMinMap = {
|
|
203
|
-
[Min in ArrayElement<typeof contrastLevels>['min']]: Extract<ArrayElement<typeof contrastLevels>, {
|
|
204
|
-
min: Min;
|
|
205
|
-
}>;
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* A mapping of all color contrast levels mins to their contrast levels. Generated from
|
|
209
|
-
* {@link contrastLevels}.
|
|
210
|
-
*
|
|
211
|
-
* @category Internal
|
|
212
|
-
*/
|
|
213
|
-
export declare const contrastLevelMinMap: ContrastLevelMinMap;
|
|
214
|
-
/**
|
|
215
|
-
* Type for {@link contrastLevelMinMap}.
|
|
216
|
-
*
|
|
217
|
-
* @category Internal
|
|
218
|
-
*/
|
|
219
|
-
export type ContrastLevelNameMap = {
|
|
220
|
-
[Name in ArrayElement<typeof contrastLevels>['name']]: Extract<ArrayElement<typeof contrastLevels>, {
|
|
221
|
-
name: Name;
|
|
222
|
-
}>;
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* A mapping of all color contrast levels mins to their contrast levels. Generated from
|
|
226
|
-
* {@link contrastLevels}.
|
|
227
|
-
*
|
|
228
|
-
* @category Internal
|
|
229
|
-
*/
|
|
230
|
-
export declare const contrastLevelNameMap: ContrastLevelNameMap;
|
package/dist/color/contrast.js
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { assertWrap, check } from '@augment-vir/assert';
|
|
2
|
-
import { arrayToObject, mapObjectValues, round, } from '@augment-vir/common';
|
|
3
|
-
// @ts-expect-error: `fontLookupAPCA` is not in the types
|
|
4
|
-
import { calcAPCA, fontLookupAPCA } from 'apca-w3';
|
|
5
|
-
/**
|
|
6
|
-
* All considered font weights in {@link FontWeight} mapped by their weight name.
|
|
7
|
-
*
|
|
8
|
-
* @category Internal
|
|
9
|
-
*/
|
|
10
|
-
export const fontWeightByName = {
|
|
11
|
-
Thin: 100,
|
|
12
|
-
ExtraLight: 200,
|
|
13
|
-
Light: 300,
|
|
14
|
-
Normal: 400,
|
|
15
|
-
Medium: 500,
|
|
16
|
-
SemiBold: 600,
|
|
17
|
-
Bold: 700,
|
|
18
|
-
ExtraBold: 800,
|
|
19
|
-
Heavy: 900,
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* All font weight names from {@link fontWeightByName}.
|
|
23
|
-
*
|
|
24
|
-
* @category Internal
|
|
25
|
-
*/
|
|
26
|
-
export const FontWeightName = mapObjectValues(fontWeightByName, (key) => key);
|
|
27
|
-
/**
|
|
28
|
-
* All considered font weights in {@link FontWeight} mapped to their weight name from
|
|
29
|
-
* {@link fontWeightByName}.
|
|
30
|
-
*
|
|
31
|
-
* @category Internal
|
|
32
|
-
*/
|
|
33
|
-
export const fontWeightToName = Object.fromEntries(Object.entries(fontWeightByName).map(([key, value,]) => [
|
|
34
|
-
value,
|
|
35
|
-
key,
|
|
36
|
-
]));
|
|
37
|
-
/**
|
|
38
|
-
* Calculate contrast for the given color combination.
|
|
39
|
-
*
|
|
40
|
-
* @category Internal
|
|
41
|
-
*/
|
|
42
|
-
export function calculateContrast({ background, foreground, }) {
|
|
43
|
-
const contrast = round(Number(calcAPCA(foreground, background)), { digits: 1 });
|
|
44
|
-
return {
|
|
45
|
-
contrast,
|
|
46
|
-
fontSizes: calculateFontSizes(contrast),
|
|
47
|
-
contrastLevel: determineContrastLevel(contrast),
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/** @category Internal */
|
|
51
|
-
export function findClosestColor(baseColor, possibleColors) {
|
|
52
|
-
return possibleColors.reduce((best, color) => {
|
|
53
|
-
const contrast = Math.abs(calculateContrast({
|
|
54
|
-
foreground: color,
|
|
55
|
-
background: baseColor,
|
|
56
|
-
}).contrast);
|
|
57
|
-
if (contrast > best.contrast) {
|
|
58
|
-
return best;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return {
|
|
62
|
-
contrast,
|
|
63
|
-
color,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
}, {
|
|
67
|
-
contrast: Infinity,
|
|
68
|
-
color: '',
|
|
69
|
-
}).color;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Find a color from an array that matches the desired contrast level.
|
|
73
|
-
*
|
|
74
|
-
* @category Internal
|
|
75
|
-
* @returns `undefined` if no color match is found.
|
|
76
|
-
*/
|
|
77
|
-
export function findColorAtContrastLevel(colors, desiredContrastLevel) {
|
|
78
|
-
const otherColors = check.isArray(colors.foreground)
|
|
79
|
-
? colors.foreground
|
|
80
|
-
: check.isArray(colors.background)
|
|
81
|
-
? colors.background
|
|
82
|
-
: new Error('No color array provided.');
|
|
83
|
-
if (otherColors instanceof Error) {
|
|
84
|
-
throw otherColors;
|
|
85
|
-
}
|
|
86
|
-
const desiredIndex = orderedContrastLevelNames.indexOf(desiredContrastLevel);
|
|
87
|
-
const bestMatch = otherColors.reduce((best, otherColor) => {
|
|
88
|
-
const contrast = calculateContrast({
|
|
89
|
-
foreground: check.isString(colors.foreground) ? colors.foreground : otherColor,
|
|
90
|
-
background: check.isString(colors.background) ? colors.background : otherColor,
|
|
91
|
-
});
|
|
92
|
-
const contrastIndex = orderedContrastLevelNames.indexOf(contrast.contrastLevel.name);
|
|
93
|
-
const distance = contrastIndex - desiredIndex;
|
|
94
|
-
if (distance > 0 || best.distance > distance) {
|
|
95
|
-
return best;
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
return {
|
|
99
|
-
color: otherColor,
|
|
100
|
-
distance,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}, {
|
|
104
|
-
distance: 0,
|
|
105
|
-
color: undefined,
|
|
106
|
-
});
|
|
107
|
-
return bestMatch.color;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Calculated needed font sizes for each font weight for the given color contrast.
|
|
111
|
-
*
|
|
112
|
-
* @category Internal
|
|
113
|
-
*/
|
|
114
|
-
export function calculateFontSizes(contrast) {
|
|
115
|
-
const fontLookup = fontLookupAPCA(contrast).slice(1);
|
|
116
|
-
const sizes = arrayToObject(fontLookup, (value, index) => {
|
|
117
|
-
return {
|
|
118
|
-
key: (index + 1) * 100,
|
|
119
|
-
value,
|
|
120
|
-
};
|
|
121
|
-
});
|
|
122
|
-
return sizes;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Finds the color contrast level for the given contrast.
|
|
126
|
-
*
|
|
127
|
-
* @category Internal
|
|
128
|
-
*/
|
|
129
|
-
export function determineContrastLevel(contrast) {
|
|
130
|
-
return assertWrap.isDefined(contrastLevels.find((threshold) => threshold.min <= Math.abs(contrast)));
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Names for each {@link ContrastLevel}.
|
|
134
|
-
*
|
|
135
|
-
* @category Internal
|
|
136
|
-
*/
|
|
137
|
-
export var ContrastLevelName;
|
|
138
|
-
(function (ContrastLevelName) {
|
|
139
|
-
ContrastLevelName["SmallBodyText"] = "small-body";
|
|
140
|
-
ContrastLevelName["BodyText"] = "body";
|
|
141
|
-
ContrastLevelName["NonBodyText"] = "non-body";
|
|
142
|
-
ContrastLevelName["Header"] = "header";
|
|
143
|
-
ContrastLevelName["Placeholder"] = "placeholder";
|
|
144
|
-
ContrastLevelName["Decoration"] = "decoration";
|
|
145
|
-
ContrastLevelName["Invisible"] = "invisible";
|
|
146
|
-
})(ContrastLevelName || (ContrastLevelName = {}));
|
|
147
|
-
/**
|
|
148
|
-
* User-facing labels for {@link ContrastLevelName}.
|
|
149
|
-
*
|
|
150
|
-
* @category Internal
|
|
151
|
-
*/
|
|
152
|
-
export const contrastLevelLabel = {
|
|
153
|
-
[ContrastLevelName.SmallBodyText]: 'Small Text',
|
|
154
|
-
[ContrastLevelName.BodyText]: 'Body Text',
|
|
155
|
-
[ContrastLevelName.NonBodyText]: 'Non-body Text',
|
|
156
|
-
[ContrastLevelName.Header]: 'Header',
|
|
157
|
-
[ContrastLevelName.Placeholder]: 'Placeholder',
|
|
158
|
-
[ContrastLevelName.Decoration]: 'Decoration',
|
|
159
|
-
[ContrastLevelName.Invisible]: 'Invisible',
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* All {@link ContrastLevelName} values in order from highest contrast to lowest.
|
|
163
|
-
*
|
|
164
|
-
* @category Internal
|
|
165
|
-
*/
|
|
166
|
-
export const orderedContrastLevelNames = [
|
|
167
|
-
ContrastLevelName.SmallBodyText,
|
|
168
|
-
ContrastLevelName.BodyText,
|
|
169
|
-
ContrastLevelName.NonBodyText,
|
|
170
|
-
ContrastLevelName.Header,
|
|
171
|
-
ContrastLevelName.Placeholder,
|
|
172
|
-
ContrastLevelName.Decoration,
|
|
173
|
-
ContrastLevelName.Invisible,
|
|
174
|
-
];
|
|
175
|
-
/**
|
|
176
|
-
* All color contrast levels corresponding to APCA bronze guidelines.
|
|
177
|
-
*
|
|
178
|
-
* @category Internal
|
|
179
|
-
*/
|
|
180
|
-
export const contrastLevels = [
|
|
181
|
-
{
|
|
182
|
-
min: 90,
|
|
183
|
-
name: ContrastLevelName.SmallBodyText,
|
|
184
|
-
description: 'Perfect for all sizes of text, even small body text.',
|
|
185
|
-
apcaName: 'small body text only',
|
|
186
|
-
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.',
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
min: 75,
|
|
190
|
-
name: ContrastLevelName.BodyText,
|
|
191
|
-
description: 'Good for regular body text and anything larger.',
|
|
192
|
-
apcaName: 'body text okay',
|
|
193
|
-
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.',
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
min: 60,
|
|
197
|
-
name: ContrastLevelName.NonBodyText,
|
|
198
|
-
description: 'Good for legible non-body text and anything larger.',
|
|
199
|
-
apcaName: 'fluent text only',
|
|
200
|
-
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.',
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
min: 45,
|
|
204
|
-
name: ContrastLevelName.Header,
|
|
205
|
-
description: 'Okay for large or headline text.',
|
|
206
|
-
apcaName: 'large & sub-fluent text',
|
|
207
|
-
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.',
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
min: 30,
|
|
211
|
-
name: ContrastLevelName.Placeholder,
|
|
212
|
-
description: 'Okay for disabled or placeholder text, copyright lines, icons, or non-text elements.',
|
|
213
|
-
apcaName: 'spot & non text only',
|
|
214
|
-
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.',
|
|
215
|
-
},
|
|
216
|
-
{
|
|
217
|
-
min: 15,
|
|
218
|
-
name: ContrastLevelName.Decoration,
|
|
219
|
-
description: 'Only okay for decorations like graphics, borders, dividers, etc. Do not use for any text.',
|
|
220
|
-
apcaName: 'no text usage',
|
|
221
|
-
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.',
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
min: 0,
|
|
225
|
-
name: ContrastLevelName.Invisible,
|
|
226
|
-
description: 'Effectively invisible for users.',
|
|
227
|
-
apcaName: 'invisible',
|
|
228
|
-
apcaDescription: 'This should be treated as invisible.',
|
|
229
|
-
},
|
|
230
|
-
];
|
|
231
|
-
/**
|
|
232
|
-
* A mapping of all color contrast levels mins to their contrast levels. Generated from
|
|
233
|
-
* {@link contrastLevels}.
|
|
234
|
-
*
|
|
235
|
-
* @category Internal
|
|
236
|
-
*/
|
|
237
|
-
export const contrastLevelMinMap = arrayToObject(contrastLevels, (contrastLevel) => {
|
|
238
|
-
return {
|
|
239
|
-
key: contrastLevel.min,
|
|
240
|
-
value: contrastLevel,
|
|
241
|
-
};
|
|
242
|
-
});
|
|
243
|
-
/**
|
|
244
|
-
* A mapping of all color contrast levels mins to their contrast levels. Generated from
|
|
245
|
-
* {@link contrastLevels}.
|
|
246
|
-
*
|
|
247
|
-
* @category Internal
|
|
248
|
-
*/
|
|
249
|
-
export const contrastLevelNameMap = arrayToObject(contrastLevels, (contrastLevel) => {
|
|
250
|
-
return {
|
|
251
|
-
key: contrastLevel.name,
|
|
252
|
-
value: contrastLevel,
|
|
253
|
-
};
|
|
254
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { type ColorThemeColor } from '../color-theme.js';
|
|
2
|
-
import { type FontWeight } from '../contrast.js';
|
|
3
|
-
/**
|
|
4
|
-
* Showcase a theme-vir color theme color.
|
|
5
|
-
*
|
|
6
|
-
* @category Internal
|
|
7
|
-
*/
|
|
8
|
-
export declare const ThemeVirColorExample: import("element-vir").DeclarativeElementDefinition<"theme-vir-color-example", {
|
|
9
|
-
color: Readonly<Pick<ColorThemeColor, "foreground" | "background">>;
|
|
10
|
-
showVarValues: boolean;
|
|
11
|
-
showVarNames: boolean;
|
|
12
|
-
showContrast: boolean;
|
|
13
|
-
fontWeight: FontWeight;
|
|
14
|
-
}, {
|
|
15
|
-
previewElement: undefined | HTMLElement;
|
|
16
|
-
forceShowEverything: boolean;
|
|
17
|
-
}, {}, "theme-vir-color-example-no-contrast-tips", "theme-vir-color-example-", readonly [], readonly []>;
|
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { assertWrap, check } from '@augment-vir/assert';
|
|
2
|
-
import { css, defineElement, html, listen, nothing, onDomCreated, unsafeCSS } from 'element-vir';
|
|
3
|
-
import { noNativeFormStyles, noNativeSpacing } from 'vira/dist/styles/native-styles.js';
|
|
4
|
-
import { calculateContrast } from '../contrast.js';
|
|
5
|
-
import { ThemeVirContrastIndicator } from './theme-vir-contrast-indicator.element.js';
|
|
6
|
-
/**
|
|
7
|
-
* Showcase a theme-vir color theme color.
|
|
8
|
-
*
|
|
9
|
-
* @category Internal
|
|
10
|
-
*/
|
|
11
|
-
export const ThemeVirColorExample = defineElement()({
|
|
12
|
-
tagName: 'theme-vir-color-example',
|
|
13
|
-
state() {
|
|
14
|
-
return {
|
|
15
|
-
previewElement: undefined,
|
|
16
|
-
forceShowEverything: false,
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
hostClasses: {
|
|
20
|
-
'theme-vir-color-example-no-contrast-tips': ({ inputs, state }) => !inputs.showContrast && !state.forceShowEverything,
|
|
21
|
-
},
|
|
22
|
-
styles: ({ hostClasses }) => css `
|
|
23
|
-
:host {
|
|
24
|
-
display: flex;
|
|
25
|
-
flex-direction: column;
|
|
26
|
-
align-items: center;
|
|
27
|
-
max-width: 100%;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.color-preview {
|
|
31
|
-
${noNativeFormStyles};
|
|
32
|
-
cursor: pointer;
|
|
33
|
-
font-size: 32px;
|
|
34
|
-
padding-left: 12px;
|
|
35
|
-
padding-right: 0;
|
|
36
|
-
border: 1px solid #ccc;
|
|
37
|
-
border-radius: 8px;
|
|
38
|
-
display: flex;
|
|
39
|
-
gap: 8px;
|
|
40
|
-
align-items: baseline;
|
|
41
|
-
|
|
42
|
-
& b {
|
|
43
|
-
margin: 12px 0;
|
|
44
|
-
font-weight: bold;
|
|
45
|
-
text-decoration: underline;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
& .square {
|
|
49
|
-
margin: 12px 0;
|
|
50
|
-
width: 24px;
|
|
51
|
-
height: 24px;
|
|
52
|
-
background-color: currentColor;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
${hostClasses['theme-vir-color-example-no-contrast-tips'].selector} {
|
|
56
|
-
& .needed-size-wrapper {
|
|
57
|
-
display: none;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
& .color-preview {
|
|
61
|
-
padding: 4px 24px;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.needed-size-wrapper {
|
|
66
|
-
align-self: stretch;
|
|
67
|
-
width: 56px;
|
|
68
|
-
position: relative;
|
|
69
|
-
overflow: hidden;
|
|
70
|
-
border-left: 1px solid #ccc;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.needed-size {
|
|
74
|
-
top: 0;
|
|
75
|
-
height: 100%;
|
|
76
|
-
display: flex;
|
|
77
|
-
align-items: center;
|
|
78
|
-
left: 6px;
|
|
79
|
-
position: absolute;
|
|
80
|
-
|
|
81
|
-
& span {
|
|
82
|
-
margin: 0 auto;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.css-var-names {
|
|
87
|
-
font-family: monospace;
|
|
88
|
-
display: flex;
|
|
89
|
-
max-width: 100%;
|
|
90
|
-
flex-direction: column;
|
|
91
|
-
opacity: 0.6;
|
|
92
|
-
margin-top: 4px;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
p {
|
|
96
|
-
${noNativeSpacing};
|
|
97
|
-
display: flex;
|
|
98
|
-
gap: 0;
|
|
99
|
-
flex-wrap: wrap;
|
|
100
|
-
|
|
101
|
-
& span:last-child {
|
|
102
|
-
margin-left: 1ex;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
${ThemeVirContrastIndicator} {
|
|
107
|
-
margin-top: 1px;
|
|
108
|
-
}
|
|
109
|
-
`,
|
|
110
|
-
render({ state, updateState, inputs }) {
|
|
111
|
-
const colorRows = [
|
|
112
|
-
'foreground',
|
|
113
|
-
'background',
|
|
114
|
-
].map((layerKey) => {
|
|
115
|
-
const keyString = [
|
|
116
|
-
inputs.color[layerKey].name,
|
|
117
|
-
inputs.showVarValues || state.forceShowEverything ? ':' : '',
|
|
118
|
-
]
|
|
119
|
-
.filter(check.isTruthy)
|
|
120
|
-
.join('');
|
|
121
|
-
const valueTemplate = inputs.showVarValues || state.forceShowEverything
|
|
122
|
-
? html `
|
|
123
|
-
<span>${inputs.color[layerKey].default}</span>
|
|
124
|
-
`
|
|
125
|
-
: nothing;
|
|
126
|
-
return html `
|
|
127
|
-
<p>
|
|
128
|
-
<span>${keyString}</span>
|
|
129
|
-
${valueTemplate}
|
|
130
|
-
</p>
|
|
131
|
-
`;
|
|
132
|
-
});
|
|
133
|
-
const cssVarNamesTemplate = inputs.showVarNames || state.forceShowEverything
|
|
134
|
-
? html `
|
|
135
|
-
<div class="css-var-names">${colorRows}</div>
|
|
136
|
-
`
|
|
137
|
-
: nothing;
|
|
138
|
-
const contrast = state.previewElement
|
|
139
|
-
? calculateContrast({
|
|
140
|
-
foreground: globalThis
|
|
141
|
-
.getComputedStyle(state.previewElement)
|
|
142
|
-
.getPropertyValue('color'),
|
|
143
|
-
background: globalThis
|
|
144
|
-
.getComputedStyle(state.previewElement)
|
|
145
|
-
.getPropertyValue('background-color'),
|
|
146
|
-
})
|
|
147
|
-
: undefined;
|
|
148
|
-
const contrastTemplate = contrast && (inputs.showContrast || state.forceShowEverything)
|
|
149
|
-
? html `
|
|
150
|
-
<${ThemeVirContrastIndicator.assign({
|
|
151
|
-
contrast,
|
|
152
|
-
fontWeight: inputs.fontWeight,
|
|
153
|
-
})}></${ThemeVirContrastIndicator}>
|
|
154
|
-
`
|
|
155
|
-
: nothing;
|
|
156
|
-
return html `
|
|
157
|
-
<button
|
|
158
|
-
${listen('click', () => {
|
|
159
|
-
updateState({
|
|
160
|
-
forceShowEverything: !state.forceShowEverything,
|
|
161
|
-
});
|
|
162
|
-
})}
|
|
163
|
-
${onDomCreated((element) => {
|
|
164
|
-
updateState({
|
|
165
|
-
previewElement: assertWrap.instanceOf(element, HTMLElement),
|
|
166
|
-
});
|
|
167
|
-
})}
|
|
168
|
-
class="color-preview"
|
|
169
|
-
style=${css `
|
|
170
|
-
color: ${unsafeCSS(inputs.color.foreground.default)};
|
|
171
|
-
background: ${unsafeCSS(inputs.color.background.default)};
|
|
172
|
-
`}
|
|
173
|
-
>
|
|
174
|
-
<div class="square"></div>
|
|
175
|
-
<b>Aa</b>
|
|
176
|
-
<div class="needed-size-wrapper">
|
|
177
|
-
<span class="needed-size">
|
|
178
|
-
<span
|
|
179
|
-
style=${css `
|
|
180
|
-
visibility: ${unsafeCSS((contrast?.fontSizes[400] || Infinity) > 150
|
|
181
|
-
? 'hidden'
|
|
182
|
-
: 'visible')};
|
|
183
|
-
font-weight: ${inputs.fontWeight};
|
|
184
|
-
font-size: ${contrast ? contrast.fontSizes[400] : 14}px;
|
|
185
|
-
`}
|
|
186
|
-
>
|
|
187
|
-
Min
|
|
188
|
-
</span>
|
|
189
|
-
</span>
|
|
190
|
-
</div>
|
|
191
|
-
</button>
|
|
192
|
-
${contrastTemplate} ${cssVarNamesTemplate}
|
|
193
|
-
`;
|
|
194
|
-
},
|
|
195
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type CalculatedContrast, type FontWeight } from '../contrast.js';
|
|
2
|
-
/**
|
|
3
|
-
* Show contrast details for a theme-vir color.
|
|
4
|
-
*
|
|
5
|
-
* @category Internal
|
|
6
|
-
*/
|
|
7
|
-
export declare const ThemeVirContrastIndicator: import("element-vir").DeclarativeElementDefinition<"theme-vir-contrast-indicator", {
|
|
8
|
-
contrast: Readonly<CalculatedContrast>;
|
|
9
|
-
fontWeight: FontWeight;
|
|
10
|
-
}, {}, {}, "theme-vir-contrast-indicator-", "theme-vir-contrast-indicator-", readonly [], readonly []>;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { classMap, css, defineElement, html, unsafeCSS } from 'element-vir';
|
|
2
|
-
import { contrastLevelLabel, ContrastLevelName, contrastLevels, } from '../contrast.js';
|
|
3
|
-
/**
|
|
4
|
-
* Show contrast details for a theme-vir color.
|
|
5
|
-
*
|
|
6
|
-
* @category Internal
|
|
7
|
-
*/
|
|
8
|
-
export const ThemeVirContrastIndicator = defineElement()({
|
|
9
|
-
tagName: 'theme-vir-contrast-indicator',
|
|
10
|
-
styles: css `
|
|
11
|
-
:host {
|
|
12
|
-
display: inline-flex;
|
|
13
|
-
max-width: 100%;
|
|
14
|
-
font-size: 12px;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
.wrapper {
|
|
18
|
-
text-align: center;
|
|
19
|
-
flex-grow: 1;
|
|
20
|
-
display: flex;
|
|
21
|
-
flex-direction: column;
|
|
22
|
-
max-width: 100%;
|
|
23
|
-
color: #aaa;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
.${unsafeCSS(ContrastLevelName.Invisible)} {
|
|
27
|
-
color: red;
|
|
28
|
-
}
|
|
29
|
-
.${unsafeCSS(ContrastLevelName.Decoration)} {
|
|
30
|
-
color: #ff6600;
|
|
31
|
-
}
|
|
32
|
-
.${unsafeCSS(ContrastLevelName.Placeholder)} {
|
|
33
|
-
color: #a5a520;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.gauge {
|
|
37
|
-
align-self: center;
|
|
38
|
-
background-color: currentColor;
|
|
39
|
-
display: flex;
|
|
40
|
-
padding: 1px;
|
|
41
|
-
gap: 1px;
|
|
42
|
-
margin-bottom: 2px;
|
|
43
|
-
/* Sure sure if I actually want to keep this. */
|
|
44
|
-
display: none;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.gauge-level {
|
|
48
|
-
width: 10px;
|
|
49
|
-
height: 2px;
|
|
50
|
-
|
|
51
|
-
&.active {
|
|
52
|
-
background-color: white;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.gauge-text + .gauge-text {
|
|
57
|
-
border-left: 1px solid #ccc;
|
|
58
|
-
padding-left: 1ex;
|
|
59
|
-
}
|
|
60
|
-
`,
|
|
61
|
-
render({ inputs }) {
|
|
62
|
-
const gaugeLevels = contrastLevels
|
|
63
|
-
.toReversed()
|
|
64
|
-
.slice(1)
|
|
65
|
-
.map((level) => {
|
|
66
|
-
return html `
|
|
67
|
-
<div
|
|
68
|
-
class="gauge-level ${classMap({
|
|
69
|
-
active: level.min <= Math.abs(inputs.contrast.contrast),
|
|
70
|
-
})}"
|
|
71
|
-
></div>
|
|
72
|
-
`;
|
|
73
|
-
});
|
|
74
|
-
const title = [
|
|
75
|
-
inputs.contrast.contrastLevel.description,
|
|
76
|
-
'\nFont weights to font sizes:',
|
|
77
|
-
JSON.stringify(inputs.contrast.fontSizes, null, 4),
|
|
78
|
-
].join('\n');
|
|
79
|
-
const fontSize = inputs.contrast.fontSizes[inputs.fontWeight] > 150
|
|
80
|
-
? '-'
|
|
81
|
-
: `${inputs.contrast.fontSizes[inputs.fontWeight]}px`;
|
|
82
|
-
return html `
|
|
83
|
-
<div title=${title} class="wrapper ${inputs.contrast.contrastLevel.name}">
|
|
84
|
-
<div class="gauge">${gaugeLevels}</div>
|
|
85
|
-
<span>
|
|
86
|
-
<span class="gauge-text">${Math.round(inputs.contrast.contrast)} Lc</span>
|
|
87
|
-
<span class="gauge-text">
|
|
88
|
-
${contrastLevelLabel[inputs.contrast.contrastLevel.name]}
|
|
89
|
-
</span>
|
|
90
|
-
<span class="gauge-text">${fontSize}</span>
|
|
91
|
-
</span>
|
|
92
|
-
</div>
|
|
93
|
-
`;
|
|
94
|
-
},
|
|
95
|
-
});
|