@frontegg/types 6.0.3-alpha.3 → 6.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.
@@ -6,6 +6,10 @@ import { LocalizationsOverrides } from './Localizations';
6
6
  import { CustomEventsOptions } from '@frontegg/redux-store';
7
7
  import { PrivateOptions } from './PrivateOptions';
8
8
  export interface FronteggAppOptions extends FronteggStoreOptions, PrivateOptions {
9
+ /**
10
+ * use this flag if you want to hide the field "Company name" from the sign up form
11
+ @deprecated, use themeOptions.loginBox.signup.hideSignUpFields.hideCompanyName
12
+ */
9
13
  withCompanyName?: boolean;
10
14
  contextOptions: ContextOptions;
11
15
  events?: CustomEventsOptions;
@@ -34,19 +34,19 @@ export interface SocialLoginsLocalization {
34
34
  */
35
35
  socialactivationButtonTextPrefix: string;
36
36
  /**
37
- * Deprecated
37
+ * @Deprecated
38
38
  * Text to be display in socialLogin buttons if rendering inside login section
39
39
  * Ex: 'Continue with {{providerName}}'
40
40
  */
41
41
  loginButtonText: string;
42
42
  /**
43
- * Deprecated
43
+ * @Deprecated
44
44
  * Text to be display in socialLogin buttons if rendering inside signup section
45
45
  * Ex: 'Login with {{providerName}}'
46
46
  */
47
47
  signupButtonText: string;
48
48
  /**
49
- * Deprecated
49
+ * @Deprecated
50
50
  * Text to be display in socialLogin buttons if rendering inside activation section
51
51
  * Ex: 'Sign up with {{providerName}}'
52
52
  */
@@ -1,6 +1,19 @@
1
+ /**
2
+ * Returns a number whose value is limited to the given range.
3
+ * @param {number} value The value to be clamped
4
+ * @param {number} min The lower boundary of the output range
5
+ * @param {number} max The upper boundary of the output range
6
+ * @returns {number} A number in the range [min, max]
7
+ */
1
8
  function clamp(value, min = 0, max = 1) {
2
9
  return Math.min(Math.max(min, value), max);
3
10
  }
11
+ /**
12
+ * Converts a color from CSS hex format to CSS rgb format.
13
+ * @param {string} color - Hex color, i.e. #nnn or #nnnnnn
14
+ * @returns {string} A CSS rgb color string
15
+ */
16
+
4
17
 
5
18
  export function hexToRgb(color) {
6
19
  color = color.substr(1);
@@ -20,8 +33,17 @@ function intToHex(int) {
20
33
  const hex = int.toString(16);
21
34
  return hex.length === 1 ? `0${hex}` : hex;
22
35
  }
36
+ /**
37
+ * Returns an object with the type and values of a color.
38
+ *
39
+ * Note: Does not support rgb % values.
40
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
41
+ * @returns {object} - A MUI color object: {type: string, values: number[]}
42
+ */
43
+
23
44
 
24
45
  export function decomposeColor(color) {
46
+ // Idempotent
25
47
  if (color.type) {
26
48
  return color;
27
49
  }
@@ -62,6 +84,14 @@ export function decomposeColor(color) {
62
84
  colorSpace
63
85
  };
64
86
  }
87
+ /**
88
+ * Converts a color object with type and values to a string.
89
+ * @param {object} color - Decomposed color
90
+ * @param {string} color.type - One of: 'rgb', 'rgba', 'hsl', 'hsla'
91
+ * @param {array} color.values - [n,n,n] or [n,n,n,n]
92
+ * @returns {string} A CSS color string
93
+ */
94
+
65
95
  export function recomposeColor(color) {
66
96
  const {
67
97
  type,
@@ -72,6 +102,7 @@ export function recomposeColor(color) {
72
102
  } = color;
73
103
 
74
104
  if (type.indexOf('rgb') !== -1) {
105
+ // Only convert the first 3 values to int (i.e. not alpha)
75
106
  values = values.map((n, i) => i < 3 ? parseInt(n, 10) : n);
76
107
  } else if (type.indexOf('hsl') !== -1) {
77
108
  values[1] = `${values[1]}%`;
@@ -86,7 +117,14 @@ export function recomposeColor(color) {
86
117
 
87
118
  return `${type}(${values})`;
88
119
  }
120
+ /**
121
+ * Converts a color from CSS rgb format to CSS hex format.
122
+ * @param {string} color - RGB color, i.e. rgb(n, n, n)
123
+ * @returns {string} A CSS rgb color string, i.e. #nnnnnn
124
+ */
125
+
89
126
  export function rgbToHex(color) {
127
+ // Idempotent
90
128
  if (color.indexOf('#') === 0) {
91
129
  return color;
92
130
  }
@@ -96,6 +134,12 @@ export function rgbToHex(color) {
96
134
  } = decomposeColor(color);
97
135
  return `#${values.map((n, i) => intToHex(i === 3 ? Math.round(255 * n) : n)).join('')}`;
98
136
  }
137
+ /**
138
+ * Converts a color from hsl format to rgb format.
139
+ * @param {string} color - HSL color values
140
+ * @returns {string} rgb color values
141
+ */
142
+
99
143
  export function hslToRgb(color) {
100
144
  color = decomposeColor(color);
101
145
  const {
@@ -121,18 +165,36 @@ export function hslToRgb(color) {
121
165
  values: rgb
122
166
  });
123
167
  }
168
+ /**
169
+ * The relative brightness of any point in a color space,
170
+ * normalized to 0 for darkest black and 1 for lightest white.
171
+ *
172
+ * Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
173
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
174
+ * @returns {number} The relative brightness of the color in the range 0 - 1
175
+ */
176
+
124
177
  export function getLuminance(color) {
125
178
  color = decomposeColor(color);
126
179
  let rgb = color.type === 'hsl' ? decomposeColor(hslToRgb(color)).values : color.values;
127
180
  rgb = rgb.map(val => {
128
181
  if (color.type !== 'color') {
129
- val /= 255;
182
+ val /= 255; // normalized
130
183
  }
131
184
 
132
185
  return val <= 0.03928 ? val / 12.92 : ((val + 0.055) / 1.055) ** 2.4;
133
- });
186
+ }); // Truncate at 3 digits
187
+
134
188
  return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3));
135
189
  }
190
+ /**
191
+ * Sets the absolute transparency of a color.
192
+ * Any existing alpha values are overwritten.
193
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
194
+ * @param {number} value - value to set the alpha channel to in the range 0 - 1
195
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
196
+ */
197
+
136
198
  export function alpha(color, value) {
137
199
  color = decomposeColor(color);
138
200
  value = clamp(value);
@@ -149,6 +211,13 @@ export function alpha(color, value) {
149
211
 
150
212
  return recomposeColor(color);
151
213
  }
214
+ /**
215
+ * Darkens a color.
216
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
217
+ * @param {number} coefficient - multiplier in the range 0 - 1
218
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
219
+ */
220
+
152
221
  export function darken(color, coefficient) {
153
222
  color = decomposeColor(color);
154
223
  coefficient = clamp(coefficient);
@@ -163,6 +232,13 @@ export function darken(color, coefficient) {
163
232
 
164
233
  return recomposeColor(color);
165
234
  }
235
+ /**
236
+ * Lightens a color.
237
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
238
+ * @param {number} coefficient - multiplier in the range 0 - 1
239
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
240
+ */
241
+
166
242
  export function lighten(color, coefficient) {
167
243
  color = decomposeColor(color);
168
244
  coefficient = clamp(coefficient);
@@ -181,6 +257,14 @@ export function lighten(color, coefficient) {
181
257
 
182
258
  return recomposeColor(color);
183
259
  }
260
+ /**
261
+ * Darken or lighten a color, depending on its luminance.
262
+ * Light colors are darkened, dark colors are lightened.
263
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
264
+ * @param {number} coefficient=0.15 - multiplier in the range 0 - 1
265
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
266
+ */
267
+
184
268
  export function emphasize(color, coefficient = 0.15) {
185
269
  return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
186
270
  }
@@ -1,5 +1,5 @@
1
1
  import { RedirectOptions } from '@frontegg/rest-api';
2
- import { EnhancedStore } from '@reduxjs/toolkit';
2
+ import { EnhancedStore } from '@frontegg/redux-store';
3
3
  export interface PrivateOptions {
4
4
  /**
5
5
  * Option to open admin portal as Preview mode without HTTP requests for demo mode purpose
@@ -92,6 +92,12 @@ export interface SignupPageComponentsTheme {
92
92
  * use this flag if you want to hide the sign up form and use only SSO or social sign ups
93
93
  */
94
94
  hideSignUpForm?: boolean;
95
+ /**
96
+ * use this flag if you want to hide the field "Company name" from the sign up form
97
+ */
98
+ hideSignUpFields?: {
99
+ hideCompanyName?: boolean;
100
+ };
95
101
  }
96
102
  export interface SignupPageThemeOptions extends LoginBoxCommonThemeOptions, SignupPageComponentsTheme {
97
103
  }
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.0.3-alpha.3
1
+ /** @license Frontegg v6.2.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -14,9 +14,22 @@ exports.lighten = lighten;
14
14
  exports.recomposeColor = recomposeColor;
15
15
  exports.rgbToHex = rgbToHex;
16
16
 
17
+ /**
18
+ * Returns a number whose value is limited to the given range.
19
+ * @param {number} value The value to be clamped
20
+ * @param {number} min The lower boundary of the output range
21
+ * @param {number} max The upper boundary of the output range
22
+ * @returns {number} A number in the range [min, max]
23
+ */
17
24
  function clamp(value, min = 0, max = 1) {
18
25
  return Math.min(Math.max(min, value), max);
19
26
  }
27
+ /**
28
+ * Converts a color from CSS hex format to CSS rgb format.
29
+ * @param {string} color - Hex color, i.e. #nnn or #nnnnnn
30
+ * @returns {string} A CSS rgb color string
31
+ */
32
+
20
33
 
21
34
  function hexToRgb(color) {
22
35
  color = color.substr(1);
@@ -36,8 +49,17 @@ function intToHex(int) {
36
49
  const hex = int.toString(16);
37
50
  return hex.length === 1 ? `0${hex}` : hex;
38
51
  }
52
+ /**
53
+ * Returns an object with the type and values of a color.
54
+ *
55
+ * Note: Does not support rgb % values.
56
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
57
+ * @returns {object} - A MUI color object: {type: string, values: number[]}
58
+ */
59
+
39
60
 
40
61
  function decomposeColor(color) {
62
+ // Idempotent
41
63
  if (color.type) {
42
64
  return color;
43
65
  }
@@ -78,6 +100,14 @@ function decomposeColor(color) {
78
100
  colorSpace
79
101
  };
80
102
  }
103
+ /**
104
+ * Converts a color object with type and values to a string.
105
+ * @param {object} color - Decomposed color
106
+ * @param {string} color.type - One of: 'rgb', 'rgba', 'hsl', 'hsla'
107
+ * @param {array} color.values - [n,n,n] or [n,n,n,n]
108
+ * @returns {string} A CSS color string
109
+ */
110
+
81
111
 
82
112
  function recomposeColor(color) {
83
113
  const {
@@ -89,6 +119,7 @@ function recomposeColor(color) {
89
119
  } = color;
90
120
 
91
121
  if (type.indexOf('rgb') !== -1) {
122
+ // Only convert the first 3 values to int (i.e. not alpha)
92
123
  values = values.map((n, i) => i < 3 ? parseInt(n, 10) : n);
93
124
  } else if (type.indexOf('hsl') !== -1) {
94
125
  values[1] = `${values[1]}%`;
@@ -103,8 +134,15 @@ function recomposeColor(color) {
103
134
 
104
135
  return `${type}(${values})`;
105
136
  }
137
+ /**
138
+ * Converts a color from CSS rgb format to CSS hex format.
139
+ * @param {string} color - RGB color, i.e. rgb(n, n, n)
140
+ * @returns {string} A CSS rgb color string, i.e. #nnnnnn
141
+ */
142
+
106
143
 
107
144
  function rgbToHex(color) {
145
+ // Idempotent
108
146
  if (color.indexOf('#') === 0) {
109
147
  return color;
110
148
  }
@@ -114,6 +152,12 @@ function rgbToHex(color) {
114
152
  } = decomposeColor(color);
115
153
  return `#${values.map((n, i) => intToHex(i === 3 ? Math.round(255 * n) : n)).join('')}`;
116
154
  }
155
+ /**
156
+ * Converts a color from hsl format to rgb format.
157
+ * @param {string} color - HSL color values
158
+ * @returns {string} rgb color values
159
+ */
160
+
117
161
 
118
162
  function hslToRgb(color) {
119
163
  color = decomposeColor(color);
@@ -140,19 +184,37 @@ function hslToRgb(color) {
140
184
  values: rgb
141
185
  });
142
186
  }
187
+ /**
188
+ * The relative brightness of any point in a color space,
189
+ * normalized to 0 for darkest black and 1 for lightest white.
190
+ *
191
+ * Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
192
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
193
+ * @returns {number} The relative brightness of the color in the range 0 - 1
194
+ */
195
+
143
196
 
144
197
  function getLuminance(color) {
145
198
  color = decomposeColor(color);
146
199
  let rgb = color.type === 'hsl' ? decomposeColor(hslToRgb(color)).values : color.values;
147
200
  rgb = rgb.map(val => {
148
201
  if (color.type !== 'color') {
149
- val /= 255;
202
+ val /= 255; // normalized
150
203
  }
151
204
 
152
205
  return val <= 0.03928 ? val / 12.92 : ((val + 0.055) / 1.055) ** 2.4;
153
- });
206
+ }); // Truncate at 3 digits
207
+
154
208
  return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3));
155
209
  }
210
+ /**
211
+ * Sets the absolute transparency of a color.
212
+ * Any existing alpha values are overwritten.
213
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
214
+ * @param {number} value - value to set the alpha channel to in the range 0 - 1
215
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
216
+ */
217
+
156
218
 
157
219
  function alpha(color, value) {
158
220
  color = decomposeColor(color);
@@ -170,6 +232,13 @@ function alpha(color, value) {
170
232
 
171
233
  return recomposeColor(color);
172
234
  }
235
+ /**
236
+ * Darkens a color.
237
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
238
+ * @param {number} coefficient - multiplier in the range 0 - 1
239
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
240
+ */
241
+
173
242
 
174
243
  function darken(color, coefficient) {
175
244
  color = decomposeColor(color);
@@ -185,6 +254,13 @@ function darken(color, coefficient) {
185
254
 
186
255
  return recomposeColor(color);
187
256
  }
257
+ /**
258
+ * Lightens a color.
259
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
260
+ * @param {number} coefficient - multiplier in the range 0 - 1
261
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
262
+ */
263
+
188
264
 
189
265
  function lighten(color, coefficient) {
190
266
  color = decomposeColor(color);
@@ -204,6 +280,14 @@ function lighten(color, coefficient) {
204
280
 
205
281
  return recomposeColor(color);
206
282
  }
283
+ /**
284
+ * Darken or lighten a color, depending on its luminance.
285
+ * Light colors are darkened, dark colors are lightened.
286
+ * @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color()
287
+ * @param {number} coefficient=0.15 - multiplier in the range 0 - 1
288
+ * @returns {string} A CSS color string. Hex input values are returned as rgb
289
+ */
290
+
207
291
 
208
292
  function emphasize(color, coefficient = 0.15) {
209
293
  return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
package/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license Frontegg v6.0.3-alpha.3
1
+ /** @license Frontegg v6.2.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@frontegg/types",
3
- "version": "6.0.3-alpha.3",
3
+ "version": "6.2.0",
4
4
  "main": "./node/index.js",
5
5
  "author": "Frontegg LTD",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@babel/runtime": "^7.17.2",
9
- "@frontegg/redux-store": "6.0.3-alpha.3",
9
+ "@frontegg/redux-store": "6.2.0",
10
10
  "csstype": "^3.0.9",
11
11
  "deepmerge": "^4.2.2"
12
12
  },