@tryghost/color-utils 0.1.27 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2022 Ghost Foundation
3
+ Copyright (c) 2013-2023 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -36,4 +36,4 @@ Follow the instructions for the top-level repo.
36
36
 
37
37
  # Copyright & License
38
38
 
39
- Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).
39
+ Copyright (c) 2013-2023 Ghost Foundation - Released under the [MIT license](LICENSE).
@@ -7,54 +7,37 @@ var Color = require('color');
7
7
  function lightenToContrastThreshold(foreground, background, contrastThreshold) {
8
8
  const foregroundColor = Color(foreground);
9
9
  const backgroundColor = Color(background);
10
-
11
- const {h,s} = foregroundColor.hsl().object();
12
-
10
+ const { h, s } = foregroundColor.hsl().object();
13
11
  let newColor = foregroundColor;
14
-
15
12
  while (newColor.contrast(backgroundColor) < contrastThreshold) {
16
13
  if (newColor.lightness() >= 100) {
17
14
  break;
18
15
  }
19
-
20
- newColor = Color({h, s, l: newColor.lightness() + 5});
16
+ newColor = Color({ h, s, l: newColor.lightness() + 5 });
21
17
  }
22
-
23
18
  return newColor;
24
19
  }
25
-
26
20
  function darkenToContrastThreshold(foreground, background, contrastThreshold) {
27
21
  const foregroundColor = Color(foreground);
28
22
  const backgroundColor = Color(background);
29
-
30
- const {h,s} = foregroundColor.hsl().object();
31
-
23
+ const { h, s } = foregroundColor.hsl().object();
32
24
  let newColor = foregroundColor;
33
-
34
25
  while (newColor.contrast(backgroundColor) < contrastThreshold) {
35
26
  if (newColor.lightness() <= 0) {
36
27
  break;
37
28
  }
38
-
39
- newColor = Color({h, s, l: newColor.lightness() - 5});
29
+ newColor = Color({ h, s, l: newColor.lightness() - 5 });
40
30
  }
41
-
42
31
  return newColor;
43
32
  }
44
-
45
33
  function textColorForBackgroundColor(background) {
46
34
  const backgroundColor = Color(background);
47
-
48
- const white = Color({r: 255, g: 255, b: 255});
49
- const black = Color({r: 0, g: 0, b: 0});
50
-
35
+ const white = Color({ r: 255, g: 255, b: 255 });
36
+ const black = Color({ r: 0, g: 0, b: 0 });
51
37
  // shared with Portal https://github.com/TryGhost/Portal/blob/317876f20d22431df15e655ea6cc197fe636615e/src/utils/contrast-color.js#L26-L29
52
- const yiq = (
53
- backgroundColor.red() * 0.299 +
38
+ const yiq = (backgroundColor.red() * 0.299 +
54
39
  backgroundColor.green() * 0.587 +
55
- backgroundColor.b() * 0.114
56
- );
57
-
40
+ backgroundColor.b() * 0.114);
58
41
  return (yiq >= 186) ? black : white;
59
42
  }
60
43
 
package/es/color-utils.js CHANGED
@@ -2128,61 +2128,40 @@ function zeroArray(arr, length) {
2128
2128
  var color = Color;
2129
2129
 
2130
2130
  function lightenToContrastThreshold(foreground, background, contrastThreshold) {
2131
- const foregroundColor = color(foreground);
2132
- const backgroundColor = color(background);
2133
- const {
2134
- h,
2135
- s
2136
- } = foregroundColor.hsl().object();
2137
- let newColor = foregroundColor;
2138
- while (newColor.contrast(backgroundColor) < contrastThreshold) {
2139
- if (newColor.lightness() >= 100) {
2140
- break;
2131
+ const foregroundColor = color(foreground);
2132
+ const backgroundColor = color(background);
2133
+ const { h, s } = foregroundColor.hsl().object();
2134
+ let newColor = foregroundColor;
2135
+ while (newColor.contrast(backgroundColor) < contrastThreshold) {
2136
+ if (newColor.lightness() >= 100) {
2137
+ break;
2138
+ }
2139
+ newColor = color({ h, s, l: newColor.lightness() + 5 });
2141
2140
  }
2142
- newColor = color({
2143
- h,
2144
- s,
2145
- l: newColor.lightness() + 5
2146
- });
2147
- }
2148
- return newColor;
2141
+ return newColor;
2149
2142
  }
2150
2143
  function darkenToContrastThreshold(foreground, background, contrastThreshold) {
2151
- const foregroundColor = color(foreground);
2152
- const backgroundColor = color(background);
2153
- const {
2154
- h,
2155
- s
2156
- } = foregroundColor.hsl().object();
2157
- let newColor = foregroundColor;
2158
- while (newColor.contrast(backgroundColor) < contrastThreshold) {
2159
- if (newColor.lightness() <= 0) {
2160
- break;
2144
+ const foregroundColor = color(foreground);
2145
+ const backgroundColor = color(background);
2146
+ const { h, s } = foregroundColor.hsl().object();
2147
+ let newColor = foregroundColor;
2148
+ while (newColor.contrast(backgroundColor) < contrastThreshold) {
2149
+ if (newColor.lightness() <= 0) {
2150
+ break;
2151
+ }
2152
+ newColor = color({ h, s, l: newColor.lightness() - 5 });
2161
2153
  }
2162
- newColor = color({
2163
- h,
2164
- s,
2165
- l: newColor.lightness() - 5
2166
- });
2167
- }
2168
- return newColor;
2154
+ return newColor;
2169
2155
  }
2170
2156
  function textColorForBackgroundColor(background) {
2171
- const backgroundColor = color(background);
2172
- const white = color({
2173
- r: 255,
2174
- g: 255,
2175
- b: 255
2176
- });
2177
- const black = color({
2178
- r: 0,
2179
- g: 0,
2180
- b: 0
2181
- });
2182
-
2183
- // shared with Portal https://github.com/TryGhost/Portal/blob/317876f20d22431df15e655ea6cc197fe636615e/src/utils/contrast-color.js#L26-L29
2184
- const yiq = backgroundColor.red() * 0.299 + backgroundColor.green() * 0.587 + backgroundColor.b() * 0.114;
2185
- return yiq >= 186 ? black : white;
2157
+ const backgroundColor = color(background);
2158
+ const white = color({ r: 255, g: 255, b: 255 });
2159
+ const black = color({ r: 0, g: 0, b: 0 });
2160
+ // shared with Portal https://github.com/TryGhost/Portal/blob/317876f20d22431df15e655ea6cc197fe636615e/src/utils/contrast-color.js#L26-L29
2161
+ const yiq = (backgroundColor.red() * 0.299 +
2162
+ backgroundColor.green() * 0.587 +
2163
+ backgroundColor.b() * 0.114);
2164
+ return (yiq >= 186) ? black : white;
2186
2165
  }
2187
2166
 
2188
2167
  export { color as Color, darkenToContrastThreshold, lightenToContrastThreshold, textColorForBackgroundColor };