pacem-less 0.51.4-cauchy → 0.51.4-cramer

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/themebuilder.js +11 -6
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.51.4-cauchy",
2
+ "version": "0.51.4-cramer",
3
3
  "name": "pacem-less",
4
4
  "homepage": "https://js.pacem.it",
5
5
  "repository": {
package/themebuilder.js CHANGED
@@ -38,6 +38,10 @@ const argv = yargs
38
38
  .option('maxcontrast', {
39
39
  type: 'number',
40
40
  description: 'The maximum WCAG contrast (1 to 21) default-to-background (default 15).',
41
+ })
42
+ .option('contrast', {
43
+ type: 'number',
44
+ description: 'The minimim WCAG contrast (1 to 21) solid color-to-background (default 4.5).',
41
45
  })
42
46
  .help()
43
47
  .argv;
@@ -86,6 +90,7 @@ const palette = Object.assign({
86
90
  }, readFile(argv.src) ?? {});
87
91
  const WCAG_MINIMUM_CONTRAST = argv.mincontrast ?? 1.5;
88
92
  const WCAG_NORMAL_TEXT_CONTRAST = 4.5;
93
+ const WCAG_NORMAL_COLOR_CONTRAST = argv.contrast ?? WCAG_NORMAL_TEXT_CONTRAST;
89
94
  const WCAG_SAFE_CONTRAST = 7;
90
95
  const WCAG_MAX_CONTRAST = argv.maxcontrast ?? 15;
91
96
  const WCAG_DISABLED_CONTRAST = 1.6;
@@ -185,7 +190,7 @@ function colorModuleDisabled(clr) {
185
190
  console.log('disabled container yields ' + Pacem.Colors.stringify(container) + ', which should contrast ' + containerTargetContrast + ' with ' + Pacem.Colors.stringify(containerBenchmarkColor));
186
191
  const containerContrast = contrastColor(container, baseContrast, preferBaseWithLighterColor);
187
192
  const active = luminanceColor(actualColor, Pacem.Colors.luminance(actualColor) + luminanceBackActiveOffset);
188
- const activeContrast = contrastColor(active, baseContrast);
193
+ const activeContrast = contrastColor(active, baseContrast, preferContrastWithLighterColor);
189
194
  const containerActive = luminanceColor(container, Pacem.Colors.luminance(container) + luminanceBackActiveOffset);
190
195
  const containerActiveContrast = contrastColor(containerActive, baseContrast);
191
196
  const emphasis = Pacem.Colors.lighten(actualColor, .1);
@@ -206,22 +211,22 @@ function colorModule(clr, name, arg2) {
206
211
  const forcedContrast = (arg2 && typeof arg2 === 'number') ? arg2 : null;
207
212
  const baseContrast = forcedContrast ?? WCAG_SAFE_CONTRAST;
208
213
  const contrastClr = arg2 && typeof arg2 === 'object' ? arg2 : null;
209
- const isColorRight = isColorLight(clr) === darkTheme;
214
+ const isColorRight = isColorLight(clr) === darkTheme && Pacem.Colors.contrastRatio(clr, backgroundModule.base) >= WCAG_NORMAL_COLOR_CONTRAST;
210
215
  const referenceColor = isColorRight ? clr
211
- : contrastColor(clr, backgroundModule.base, WCAG_NORMAL_TEXT_CONTRAST, darkTheme);
216
+ : contrastColor(clr, backgroundModule.base, WCAG_NORMAL_COLOR_CONTRAST, darkTheme);
212
217
  let actualColor = contrastClr ? clr : referenceColor;
213
218
  if (isDesaturated) {
214
219
  actualColor = desaturateColor(actualColor);
215
220
  }
216
221
  const luminanceBackActiveOffset = darkTheme ? .1 : -.06;
217
222
  const contrastForeActive = forcedContrast ?? WCAG_SAFE_CONTRAST;
218
- const contrast = contrastClr ?? contrastColor(actualColor, baseContrast);
223
+ const contrast = contrastClr ?? contrastColor(actualColor, baseContrast, !darkTheme);
219
224
  const containerTargetContrast = WCAG_MINIMUM_CONTRAST;
220
225
  const containerBenchmarkColor = backgroundModule.base;
221
226
  const container = contrastColor(actualColor, containerBenchmarkColor, containerTargetContrast, !darkTheme);
222
227
  const containerContrast = contrastColor(container, WCAG_NORMAL_TEXT_CONTRAST);
223
228
  const active = luminanceColor(actualColor, Pacem.Colors.luminance(actualColor) + luminanceBackActiveOffset);
224
- const activeContrast = contrastColor(active, contrastForeActive);
229
+ const activeContrast = contrastColor(active, contrastForeActive, !darkTheme);
225
230
  const containerActive = luminanceColor(container, Pacem.Colors.luminance(container) + luminanceBackActiveOffset);
226
231
  const containerActiveContrast = contrastColor(containerActive, contrastForeActive);
227
232
  const emphasis = isDesaturated ? Pacem.Colors.lighten(actualColor, .1) : Pacem.Colors.saturate(actualColor, 1.2);
@@ -267,7 +272,7 @@ const rootColor = 'root' in palette ? Pacem.Colors.parse(palette['root']) : Pace
267
272
  rootModule = colorModuleBackground(rootColor, 'root');
268
273
  pushLessVariables('root', rootModule);
269
274
  if ('default' in palette) {
270
- const defaultColor = contrastColor(desaturateColor(Pacem.Colors.parse(palette['default'])), rootModule.base, WCAG_MAX_CONTRAST, darkTheme);
275
+ const defaultColor = contrastColor(Pacem.Colors.parse(palette['default']), rootModule.base, WCAG_MAX_CONTRAST, darkTheme);
271
276
  const defaultModule = colorModule(defaultColor, 'default');
272
277
  pushLessVariables('default', defaultModule);
273
278
  }