@digdir/designsystemet 0.1.0-alpha.13 → 0.1.0-alpha.15
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/bin/designsystemet.js +32 -3439
- package/dist/src/colors/colorUtils.js +301 -343
- package/dist/src/colors/index.js +3 -607
- package/dist/src/colors/themeUtils.js +319 -348
- package/dist/src/colors/types.js +1 -1
- package/dist/src/init/createTokensPackage.js +230 -0
- package/dist/src/init/generateMetadataJson.js +16 -0
- package/dist/src/init/generateThemesJson.js +50 -0
- package/dist/src/init/index.js +7 -0
- package/dist/src/init/nextStepsMarkdown.js +90 -0
- package/dist/src/init/template/default-files/README.md +10 -0
- package/dist/src/init/template/default-files/design-tokens/README.md +3 -0
- package/dist/src/init/template/default-files/design-tokens/primitives/globals.json +197 -0
- package/dist/src/init/template/default-files/design-tokens/primitives/typography/default.json +86 -0
- package/dist/src/init/template/default-files/design-tokens/semantic/color.json +562 -0
- package/dist/src/init/template/default-files/design-tokens/semantic/style.json +543 -0
- package/dist/src/init/template/prettier.config.js +7 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +314 -0
- package/dist/src/init/template/template-files/package.json +23 -0
- package/dist/src/init/utils.js +11 -0
- package/dist/src/migrations/beta-to-v1.js +341 -407
- package/dist/src/migrations/codemods/css/plugins.js +36 -42
- package/dist/src/migrations/codemods/css/run.js +20 -17
- package/dist/src/migrations/codemods/jsx/classname-prefix.js +63 -59
- package/dist/src/migrations/codemods/jsx/run.js +20 -20
- package/dist/src/migrations/index.js +5 -436
- package/dist/src/migrations/react-beta-to-v1.js +4 -27
- package/dist/src/test/a.css +39 -0
- package/dist/src/test/jsx-test.js +12 -0
- package/dist/src/tokens/actions.js +23 -2176
- package/dist/src/tokens/build.js +54 -2974
- package/dist/src/tokens/configs.js +234 -2874
- package/dist/src/tokens/formats/css.js +153 -2632
- package/dist/src/tokens/formats/js-tokens.js +28 -42
- package/dist/src/tokens/transformers.js +44 -82
- package/dist/src/tokens/utils/noCase.js +26 -28
- package/dist/src/tokens/utils/permutateThemes.js +65 -217
- package/dist/src/tokens/utils/utils.js +25 -14
- package/package.json +16 -23
- package/LICENSE +0 -7
- package/dist/bin/designsystemet.js.map +0 -1
- package/dist/src/colors/colorUtils.js.map +0 -1
- package/dist/src/colors/index.js.map +0 -1
- package/dist/src/colors/themeUtils.js.map +0 -1
- package/dist/src/colors/types.js.map +0 -1
- package/dist/src/migrations/beta-to-v1.js.map +0 -1
- package/dist/src/migrations/codemods/css/plugins.js.map +0 -1
- package/dist/src/migrations/codemods/css/run.js.map +0 -1
- package/dist/src/migrations/codemods/jsx/classname-prefix.js.map +0 -1
- package/dist/src/migrations/codemods/jsx/run.js.map +0 -1
- package/dist/src/migrations/index.js.map +0 -1
- package/dist/src/migrations/react-beta-to-v1.js.map +0 -1
- package/dist/src/tokens/actions.js.map +0 -1
- package/dist/src/tokens/build.js.map +0 -1
- package/dist/src/tokens/configs.js.map +0 -1
- package/dist/src/tokens/formats/css.js.map +0 -1
- package/dist/src/tokens/formats/js-tokens.js.map +0 -1
- package/dist/src/tokens/transformers.js.map +0 -1
- package/dist/src/tokens/utils/noCase.js.map +0 -1
- package/dist/src/tokens/utils/permutateThemes.js.map +0 -1
- package/dist/src/tokens/utils/utils.js.map +0 -1
|
@@ -1,365 +1,336 @@
|
|
|
1
|
-
// src/colors/themeUtils.ts
|
|
2
1
|
import { BackgroundColor, Color, Theme } from "@adobe/leonardo-contrast-colors";
|
|
3
|
-
import { Hsluv as Hsluv2 } from "hsluv";
|
|
4
|
-
|
|
5
|
-
// src/colors/colorUtils.ts
|
|
6
2
|
import { Hsluv } from "hsluv";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const textSubLightLightness = contrastMode === "aa" ? 42 : 30;
|
|
102
|
-
const textDefLightLightness = contrastMode === "aa" ? 18 : 12;
|
|
103
|
-
const textSubDarkLightness = contrastMode === "aa" ? 67 : 80;
|
|
104
|
-
const textDefDarkLightness = contrastMode === "aa" ? 90 : 94;
|
|
105
|
-
let lightnessScale = [];
|
|
106
|
-
if (mode === "light") {
|
|
107
|
-
lightnessScale = [100, 96, 90, 84, 78, 76, 54, 33, textSubLightLightness, textDefLightLightness];
|
|
108
|
-
} else if (mode === "dark") {
|
|
109
|
-
lightnessScale = [10, 14, 20, 26, 32, 35, 47, 77, textSubDarkLightness, textDefDarkLightness];
|
|
110
|
-
} else {
|
|
111
|
-
lightnessScale = [1, 6, 14, 20, 26, 58, 70, 82, 80, 95];
|
|
112
|
-
}
|
|
113
|
-
const getColorContrasts = (color2, lightnessScale2, backgroundColor) => {
|
|
114
|
-
return lightnessScale2.map((lightness) => getContrastFromLightness(lightness, color2, backgroundColor));
|
|
115
|
-
};
|
|
116
|
-
return new Color({
|
|
117
|
-
name: "color",
|
|
118
|
-
colorKeys: [color],
|
|
119
|
-
ratios: [
|
|
120
|
-
...getColorContrasts(color, lightnessScale.slice(0, 8), leoBackgroundColor.colorKeys[0]),
|
|
121
|
-
baseDefaultContrast,
|
|
122
|
-
baseHoverContrast,
|
|
123
|
-
baseActiveContrast,
|
|
124
|
-
...getColorContrasts(color, lightnessScale.slice(8), leoBackgroundColor.colorKeys[0])
|
|
125
|
-
]
|
|
126
|
-
});
|
|
3
|
+
import { getContrastFromHex, getContrastFromLightness, getLightnessFromHex } from "./colorUtils.js";
|
|
4
|
+
const blueBaseColor = '#0A71C0';
|
|
5
|
+
const greenBaseColor = '#078D19';
|
|
6
|
+
const orangeBaseColor = '#CA5C21';
|
|
7
|
+
const purpleBaseColor = '#663299';
|
|
8
|
+
const redBaseColor = '#C01B1B';
|
|
9
|
+
const yellowBaseColor = '#EABF28';
|
|
10
|
+
/**
|
|
11
|
+
* Generates a Leonardo theme color that is used to create a Leonardo Theme
|
|
12
|
+
*
|
|
13
|
+
* @param color CssColor
|
|
14
|
+
* @param mode Light, Dark or Contrastmode
|
|
15
|
+
* @param contrastMode Contrast mode
|
|
16
|
+
* @returns
|
|
17
|
+
*/ const generateThemeColor = (color, mode, contrastMode = 'aa')=>{
|
|
18
|
+
const leoBackgroundColor = new BackgroundColor({
|
|
19
|
+
name: 'backgroundColor',
|
|
20
|
+
colorKeys: [
|
|
21
|
+
'#ffffff'
|
|
22
|
+
],
|
|
23
|
+
ratios: [
|
|
24
|
+
1
|
|
25
|
+
]
|
|
26
|
+
});
|
|
27
|
+
let colorLightness = getLightnessFromHex(color);
|
|
28
|
+
if (mode === 'dark' || mode === 'contrast') {
|
|
29
|
+
color = getBaseColor(color);
|
|
30
|
+
colorLightness = colorLightness <= 30 ? 70 : 100 - colorLightness;
|
|
31
|
+
}
|
|
32
|
+
const multiplier = colorLightness <= 30 ? -8 : 8;
|
|
33
|
+
const baseDefaultContrast = getContrastFromLightness(colorLightness, color, leoBackgroundColor.colorKeys[0]);
|
|
34
|
+
const baseHoverContrast = getContrastFromLightness(colorLightness - multiplier, color, leoBackgroundColor.colorKeys[0]);
|
|
35
|
+
const baseActiveContrast = getContrastFromLightness(colorLightness - multiplier * 2, color, leoBackgroundColor.colorKeys[0]);
|
|
36
|
+
const textSubLightLightness = contrastMode === 'aa' ? 42 : 30;
|
|
37
|
+
const textDefLightLightness = contrastMode === 'aa' ? 18 : 12;
|
|
38
|
+
const textSubDarkLightness = contrastMode === 'aa' ? 67 : 80;
|
|
39
|
+
const textDefDarkLightness = contrastMode === 'aa' ? 90 : 94;
|
|
40
|
+
let lightnessScale = [];
|
|
41
|
+
if (mode === 'light') {
|
|
42
|
+
lightnessScale = [
|
|
43
|
+
100,
|
|
44
|
+
96,
|
|
45
|
+
90,
|
|
46
|
+
84,
|
|
47
|
+
78,
|
|
48
|
+
76,
|
|
49
|
+
54,
|
|
50
|
+
33,
|
|
51
|
+
textSubLightLightness,
|
|
52
|
+
textDefLightLightness
|
|
53
|
+
];
|
|
54
|
+
} else if (mode === 'dark') {
|
|
55
|
+
lightnessScale = [
|
|
56
|
+
10,
|
|
57
|
+
14,
|
|
58
|
+
20,
|
|
59
|
+
26,
|
|
60
|
+
32,
|
|
61
|
+
35,
|
|
62
|
+
47,
|
|
63
|
+
77,
|
|
64
|
+
textSubDarkLightness,
|
|
65
|
+
textDefDarkLightness
|
|
66
|
+
];
|
|
67
|
+
} else {
|
|
68
|
+
lightnessScale = [
|
|
69
|
+
1,
|
|
70
|
+
6,
|
|
71
|
+
14,
|
|
72
|
+
20,
|
|
73
|
+
26,
|
|
74
|
+
58,
|
|
75
|
+
70,
|
|
76
|
+
82,
|
|
77
|
+
80,
|
|
78
|
+
95
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
const getColorContrasts = (color, lightnessScale, backgroundColor)=>{
|
|
82
|
+
return lightnessScale.map((lightness)=>getContrastFromLightness(lightness, color, backgroundColor));
|
|
83
|
+
};
|
|
84
|
+
return new Color({
|
|
85
|
+
name: 'color',
|
|
86
|
+
colorKeys: [
|
|
87
|
+
color
|
|
88
|
+
],
|
|
89
|
+
ratios: [
|
|
90
|
+
...getColorContrasts(color, lightnessScale.slice(0, 8), leoBackgroundColor.colorKeys[0]),
|
|
91
|
+
baseDefaultContrast,
|
|
92
|
+
baseHoverContrast,
|
|
93
|
+
baseActiveContrast,
|
|
94
|
+
...getColorContrasts(color, lightnessScale.slice(8), leoBackgroundColor.colorKeys[0])
|
|
95
|
+
]
|
|
96
|
+
});
|
|
127
97
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
98
|
+
/**
|
|
99
|
+
*
|
|
100
|
+
* Generates a color scale based on a base color and a mode.
|
|
101
|
+
*
|
|
102
|
+
* @param color The base color that is used to generate the color scale
|
|
103
|
+
* @param mode The mode of the theme
|
|
104
|
+
*/ export const generateScaleForColor = (color, mode, contrastMode = 'aa')=>{
|
|
105
|
+
const themeColor = generateThemeColor(color, mode, contrastMode);
|
|
106
|
+
const leoBackgroundColor = new BackgroundColor({
|
|
107
|
+
name: 'backgroundColor',
|
|
108
|
+
colorKeys: [
|
|
109
|
+
'#ffffff'
|
|
110
|
+
],
|
|
111
|
+
ratios: [
|
|
112
|
+
1
|
|
113
|
+
]
|
|
114
|
+
});
|
|
115
|
+
const theme = new Theme({
|
|
116
|
+
colors: [
|
|
117
|
+
themeColor
|
|
118
|
+
],
|
|
119
|
+
backgroundColor: leoBackgroundColor,
|
|
120
|
+
lightness: 100
|
|
121
|
+
});
|
|
122
|
+
const outputArray = [];
|
|
123
|
+
for(let i = 0; i < theme.contrastColorValues.length; i++){
|
|
124
|
+
outputArray.push({
|
|
125
|
+
hex: theme.contrastColorValues[i],
|
|
126
|
+
number: i + 1,
|
|
127
|
+
name: getColorNameFromNumber(i + 1)
|
|
128
|
+
});
|
|
129
|
+
}
|
|
142
130
|
outputArray.push({
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
131
|
+
hex: calculateContrastOneColor(theme.contrastColorValues[8]),
|
|
132
|
+
number: 14,
|
|
133
|
+
name: getColorNameFromNumber(14)
|
|
146
134
|
});
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
name: getColorNameFromNumber(15)
|
|
157
|
-
});
|
|
158
|
-
if (mode === "light") {
|
|
159
|
-
outputArray[8].hex = color;
|
|
160
|
-
}
|
|
161
|
-
return outputArray;
|
|
162
|
-
};
|
|
163
|
-
var generateThemeForColor = (color, contrastMode = "aa") => {
|
|
164
|
-
const lightScale = generateScaleForColor(color, "light", contrastMode);
|
|
165
|
-
const darkScale = generateScaleForColor(color, "dark", contrastMode);
|
|
166
|
-
const contrastScale = generateScaleForColor(color, "contrast", contrastMode);
|
|
167
|
-
return {
|
|
168
|
-
light: lightScale,
|
|
169
|
-
dark: darkScale,
|
|
170
|
-
contrast: contrastScale
|
|
171
|
-
};
|
|
135
|
+
outputArray.push({
|
|
136
|
+
hex: calculateContrastTwoColor(theme.contrastColorValues[8]),
|
|
137
|
+
number: 15,
|
|
138
|
+
name: getColorNameFromNumber(15)
|
|
139
|
+
});
|
|
140
|
+
if (mode === 'light') {
|
|
141
|
+
outputArray[8].hex = color;
|
|
142
|
+
}
|
|
143
|
+
return outputArray;
|
|
172
144
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
};
|
|
145
|
+
/**
|
|
146
|
+
*
|
|
147
|
+
* Generates a color theme based on a base color. Light, Dark and Contrast scales are includes.
|
|
148
|
+
*
|
|
149
|
+
* @param color The base color that is used to generate the color theme
|
|
150
|
+
*/ export const generateThemeForColor = (color, contrastMode = 'aa')=>{
|
|
151
|
+
const lightScale = generateScaleForColor(color, 'light', contrastMode);
|
|
152
|
+
const darkScale = generateScaleForColor(color, 'dark', contrastMode);
|
|
153
|
+
const contrastScale = generateScaleForColor(color, 'contrast', contrastMode);
|
|
154
|
+
return {
|
|
155
|
+
light: lightScale,
|
|
156
|
+
dark: darkScale,
|
|
157
|
+
contrast: contrastScale
|
|
158
|
+
};
|
|
188
159
|
};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
160
|
+
export const generateGlobalColors = ({ contrastMode = 'aa' })=>{
|
|
161
|
+
const blueTheme = generateThemeForColor(blueBaseColor, contrastMode);
|
|
162
|
+
const greenTheme = generateThemeForColor(greenBaseColor, contrastMode);
|
|
163
|
+
const orangeTheme = generateThemeForColor(orangeBaseColor, contrastMode);
|
|
164
|
+
const purpleTheme = generateThemeForColor(purpleBaseColor, contrastMode);
|
|
165
|
+
const redTheme = generateThemeForColor(redBaseColor, contrastMode);
|
|
166
|
+
const yellowTheme = generateThemeForColor(yellowBaseColor, contrastMode);
|
|
167
|
+
return {
|
|
168
|
+
blue: blueTheme,
|
|
169
|
+
green: greenTheme,
|
|
170
|
+
orange: orangeTheme,
|
|
171
|
+
purple: purpleTheme,
|
|
172
|
+
red: redTheme,
|
|
173
|
+
yellow: yellowTheme
|
|
174
|
+
};
|
|
202
175
|
};
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
176
|
+
/**
|
|
177
|
+
* This function generates a complete theme for a set of colors.
|
|
178
|
+
*
|
|
179
|
+
* @param colors Which colors to generate the theme for
|
|
180
|
+
* @param contrastMode The contrast mode to use
|
|
181
|
+
* @returns
|
|
182
|
+
*/ export const generateColorTheme = ({ colors, contrastMode = 'aa' })=>{
|
|
183
|
+
const accentTheme = generateThemeForColor(colors.accent, contrastMode);
|
|
184
|
+
const neutralTheme = generateThemeForColor(colors.neutral, contrastMode);
|
|
185
|
+
const brand1Theme = generateThemeForColor(colors.brand1, contrastMode);
|
|
186
|
+
const brand2Theme = generateThemeForColor(colors.brand2, contrastMode);
|
|
187
|
+
const brand3Theme = generateThemeForColor(colors.brand3, contrastMode);
|
|
188
|
+
return {
|
|
189
|
+
accent: accentTheme,
|
|
190
|
+
neutral: neutralTheme,
|
|
191
|
+
brand1: brand1Theme,
|
|
192
|
+
brand2: brand2Theme,
|
|
193
|
+
brand3: brand3Theme
|
|
194
|
+
};
|
|
208
195
|
};
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* This function calculates a color that can be used as a strong contrast color to a base color.
|
|
199
|
+
*
|
|
200
|
+
* @param baseColor The base color
|
|
201
|
+
*/ export const calculateContrastOneColor = (baseColor)=>{
|
|
202
|
+
const contrastWhite = getContrastFromHex(baseColor, '#ffffff');
|
|
203
|
+
const contrastBlack = getContrastFromHex(baseColor, '#000000');
|
|
204
|
+
const lightness = contrastWhite >= contrastBlack ? 100 : 0;
|
|
205
|
+
// const color = createColorWithLightness(baseColor, lightness);
|
|
206
|
+
return lightness === 0 ? '#000000' : '#ffffff';
|
|
218
207
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
208
|
+
/**
|
|
209
|
+
*
|
|
210
|
+
* This function calculates a color that can be used as a subtle contrast color to a base color.
|
|
211
|
+
*
|
|
212
|
+
* @param color The base color
|
|
213
|
+
*/ export const calculateContrastTwoColor = (color)=>{
|
|
214
|
+
const contrastWhite = getContrastFromHex(color, '#ffffff');
|
|
215
|
+
const contrastBlack = getContrastFromHex(color, '#000000');
|
|
216
|
+
const lightness = getLightnessFromHex(color);
|
|
217
|
+
const doubleALightnessModifier = lightness <= 40 ? 60 : lightness >= 60 ? 60 : 50;
|
|
218
|
+
let targetLightness = 0;
|
|
219
|
+
const contrastDirection = contrastWhite >= contrastBlack ? 'lighten' : 'darken';
|
|
220
|
+
targetLightness = contrastDirection === 'lighten' ? lightness + doubleALightnessModifier : lightness - doubleALightnessModifier;
|
|
221
|
+
return createColorWithLightness(color, targetLightness);
|
|
230
222
|
};
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
223
|
+
/**
|
|
224
|
+
*
|
|
225
|
+
* This function checks if white or black text can be used on 2 different colors at 4.5:1 contrast.
|
|
226
|
+
*
|
|
227
|
+
* @param baseDefaultColor Base default color
|
|
228
|
+
* @param baseActiveColor Base active color
|
|
229
|
+
*/ export const canTextBeUsedOnColors = (baseDefaultColor, baseActiveColor)=>{
|
|
230
|
+
const defaultAgainstWhite = getContrastFromHex(baseDefaultColor, '#ffffff');
|
|
231
|
+
const defaultAgainstBlack = getContrastFromHex(baseDefaultColor, '#000000');
|
|
232
|
+
const activeAgainstWhite = getContrastFromHex(baseActiveColor, '#ffffff');
|
|
233
|
+
const activeAgainstBlack = getContrastFromHex(baseActiveColor, '#000000');
|
|
234
|
+
if (defaultAgainstWhite >= 4.5 && activeAgainstWhite >= 4.5) {
|
|
235
|
+
return true;
|
|
236
|
+
} else if (defaultAgainstBlack >= 4.5 && activeAgainstBlack >= 4.5) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
248
240
|
};
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* This function creates a color with a specific lightness value.
|
|
244
|
+
*
|
|
245
|
+
* @param color The base color
|
|
246
|
+
* @param lightness The lightness value from 0 to 100
|
|
247
|
+
*/ export const createColorWithLightness = (color, lightness)=>{
|
|
248
|
+
const leoBackgroundColor = new BackgroundColor({
|
|
249
|
+
name: 'backgroundColor',
|
|
250
|
+
colorKeys: [
|
|
251
|
+
'#ffffff'
|
|
252
|
+
],
|
|
253
|
+
ratios: [
|
|
254
|
+
1
|
|
255
|
+
]
|
|
256
|
+
});
|
|
257
|
+
const colors = new Color({
|
|
258
|
+
name: 'color',
|
|
259
|
+
colorKeys: [
|
|
260
|
+
color
|
|
261
|
+
],
|
|
262
|
+
ratios: [
|
|
263
|
+
getContrastFromLightness(lightness, color, '#ffffff')
|
|
264
|
+
]
|
|
265
|
+
});
|
|
266
|
+
const theme = new Theme({
|
|
267
|
+
colors: [
|
|
268
|
+
colors
|
|
269
|
+
],
|
|
270
|
+
backgroundColor: leoBackgroundColor,
|
|
271
|
+
lightness: 100
|
|
272
|
+
});
|
|
273
|
+
return theme.contrastColorValues[0];
|
|
268
274
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* This function returns the color number based on the color name.
|
|
278
|
+
*
|
|
279
|
+
* @param name The name of the color
|
|
280
|
+
*/ export const getColorNumberFromName = (name)=>{
|
|
281
|
+
const colorMap = {
|
|
282
|
+
'Background Default': 1,
|
|
283
|
+
'Background Subtle': 2,
|
|
284
|
+
'Surface Default': 3,
|
|
285
|
+
'Surface Hover': 4,
|
|
286
|
+
'Surface Active': 5,
|
|
287
|
+
'Border Subtle': 6,
|
|
288
|
+
'Border Default': 7,
|
|
289
|
+
'Border Strong': 8,
|
|
290
|
+
'Base Default': 9,
|
|
291
|
+
'Base Hover': 10,
|
|
292
|
+
'Base Active': 11,
|
|
293
|
+
'Text Subtle': 12,
|
|
294
|
+
'Text Default': 13,
|
|
295
|
+
'Contrast Default': 14,
|
|
296
|
+
'Contrast Subtle': 15
|
|
297
|
+
};
|
|
298
|
+
return colorMap[name];
|
|
288
299
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
300
|
+
/**
|
|
301
|
+
*
|
|
302
|
+
* This function returns the color name based on the color number.
|
|
303
|
+
*
|
|
304
|
+
* @param number The number of the color
|
|
305
|
+
*/ export const getColorNameFromNumber = (number)=>{
|
|
306
|
+
const colorMap = {
|
|
307
|
+
1: 'Background Default',
|
|
308
|
+
2: 'Background Subtle',
|
|
309
|
+
3: 'Surface Default',
|
|
310
|
+
4: 'Surface Hover',
|
|
311
|
+
5: 'Surface Active',
|
|
312
|
+
6: 'Border Subtle',
|
|
313
|
+
7: 'Border Default',
|
|
314
|
+
8: 'Border Strong',
|
|
315
|
+
9: 'Base Default',
|
|
316
|
+
10: 'Base Hover',
|
|
317
|
+
11: 'Base Active',
|
|
318
|
+
12: 'Text Subtle',
|
|
319
|
+
13: 'Text Default',
|
|
320
|
+
14: 'Contrast Default',
|
|
321
|
+
15: 'Contrast Subtle'
|
|
322
|
+
};
|
|
323
|
+
return colorMap[number];
|
|
295
324
|
};
|
|
296
|
-
|
|
297
|
-
|
|
325
|
+
export const getBaseColor = (color)=>{
|
|
326
|
+
const conv = new Hsluv();
|
|
327
|
+
conv.hex = color;
|
|
328
|
+
conv.hexToHsluv();
|
|
329
|
+
// conv.hsluv_l = 100 - conv.hsluv_l;
|
|
330
|
+
// conv.hsluv_s = getSaturationForDarkMode(color, conv.hsluv_s);
|
|
331
|
+
conv.hsluvToHex();
|
|
332
|
+
return conv.hex;
|
|
298
333
|
};
|
|
299
|
-
export {
|
|
300
|
-
|
|
301
|
-
calculateContrastTwoColor,
|
|
302
|
-
canTextBeUsedOnColors,
|
|
303
|
-
createColorWithLightness,
|
|
304
|
-
generateColorTheme,
|
|
305
|
-
generateGlobalColors,
|
|
306
|
-
generateScaleForColor,
|
|
307
|
-
generateThemeForColor,
|
|
308
|
-
getBaseColor,
|
|
309
|
-
getColorNameFromNumber,
|
|
310
|
-
getColorNumberFromName,
|
|
311
|
-
getCssVariable
|
|
334
|
+
export const getCssVariable = (colorType, colorNumber)=>{
|
|
335
|
+
return `--ds-${colorType}-${getColorNameFromNumber(colorNumber).toLowerCase().replace(/\s/g, '-')}`;
|
|
312
336
|
};
|
|
313
|
-
/*! Bundled license information:
|
|
314
|
-
|
|
315
|
-
colorparsley/src/colorparsley.js:
|
|
316
|
-
(** @preserve
|
|
317
|
-
///// CoLoR PaRsLeY a simple set of color parsing thingies!
|
|
318
|
-
///// Beta 0.1.8 Revision date: June 04, 2022
|
|
319
|
-
/////
|
|
320
|
-
///// Functions to parse color values and return array
|
|
321
|
-
///// Copyright (c) 2019-2022 by Andrew Somers. All Rights Reserved.
|
|
322
|
-
///// LICENSE: AGPL 3
|
|
323
|
-
///// CONTACT: Please use the ISSUES or DISCUSSIONS tab at:
|
|
324
|
-
///// https://github.com/Myndex/colorparsley/
|
|
325
|
-
/////
|
|
326
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
327
|
-
/////
|
|
328
|
-
///// IMPORT:
|
|
329
|
-
///// import { colorParsley } from 'colorparsley';
|
|
330
|
-
/////
|
|
331
|
-
///// let rgbaArray = colorParsley('#abcdef');
|
|
332
|
-
/////
|
|
333
|
-
///// Output as array: [r,g,b,a,isValid,colorspace]
|
|
334
|
-
///// Example: [123,123,123,1.0,true,'sRGB']
|
|
335
|
-
// *)
|
|
336
|
-
|
|
337
|
-
apca-w3/src/apca-w3.js:
|
|
338
|
-
(** @preserve
|
|
339
|
-
///// SAPC APCA - Advanced Perceptual Contrast Algorithm
|
|
340
|
-
///// Beta 0.1.9 W3 • contrast function only
|
|
341
|
-
///// DIST: W3 • Revision date: July 3, 2022
|
|
342
|
-
///// Function to parse color values and determine Lc contrast
|
|
343
|
-
///// Copyright © 2019-2022 by Andrew Somers. All Rights Reserved.
|
|
344
|
-
///// LICENSE: W3 LICENSE
|
|
345
|
-
///// CONTACT: Please use the ISSUES or DISCUSSIONS tab at:
|
|
346
|
-
///// https://github.com/Myndex/SAPC-APCA/
|
|
347
|
-
/////
|
|
348
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
349
|
-
/////
|
|
350
|
-
///// MINIMAL IMPORTS:
|
|
351
|
-
///// import { APCAcontrast, sRGBtoY, displayP3toY,
|
|
352
|
-
///// calcAPCA, fontLookupAPCA } from 'apca-w3';
|
|
353
|
-
///// import { colorParsley } from 'colorparsley';
|
|
354
|
-
/////
|
|
355
|
-
///// FORWARD CONTRAST USAGE:
|
|
356
|
-
///// Lc = APCAcontrast( sRGBtoY( TEXTcolor ) , sRGBtoY( BACKGNDcolor ) );
|
|
357
|
-
///// Where the colors are sent as an rgba array [255,255,255,1]
|
|
358
|
-
/////
|
|
359
|
-
///// Retrieving an array of font sizes for the contrast:
|
|
360
|
-
///// fontArray = fontLookupAPCA(Lc);
|
|
361
|
-
/////
|
|
362
|
-
///// Live Demonstrator at https://www.myndex.com/APCA/
|
|
363
|
-
// *)
|
|
364
|
-
*/
|
|
365
|
-
//# sourceMappingURL=themeUtils.js.map
|