dtable-ui-component 5.1.1-alpha.1 → 5.1.2

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.
@@ -4,33 +4,39 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.toPercentage = exports.rgbaToHex = exports.isLightColor = exports.hexToRgba = exports.getInitialHexVal = void 0;
7
+ const defaultColor = '#ffffff';
7
8
  const hexRegex = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/i;
8
9
  const rgbaRegex = /^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(0|1|0?\.\d+))?\s*\)$/i;
9
10
  const hexToRgba = color => {
10
- if (rgbaRegex.test(color)) return color;
11
- let r;
12
- let g;
13
- let b;
14
- let a = 1;
15
- const hex = color.replace(/^#/, '');
16
- if (hex.length === 6 || hex.length === 8) {
17
- r = parseInt(hex.slice(0, 2), 16);
18
- g = parseInt(hex.slice(2, 4), 16);
19
- b = parseInt(hex.slice(4, 6), 16);
20
- a = hex.length === 8 ? Math.round(parseInt(hex.slice(6, 8), 16) / 255 * 100) / 100 : 1;
21
- } else if (hex.length === 3) {
22
- r = parseInt(hex[0] + hex[0], 16);
23
- g = parseInt(hex[1] + hex[1], 16);
24
- b = parseInt(hex[2] + hex[2], 16);
25
- } else {
26
- throw new Error('Invalid HEX color.');
11
+ try {
12
+ if (rgbaRegex.test(color)) return color;
13
+ let r;
14
+ let g;
15
+ let b;
16
+ let a = 1;
17
+ const hex = color.replace(/^#/, '');
18
+ if (hex.length === 6 || hex.length === 8) {
19
+ r = parseInt(hex.slice(0, 2), 16);
20
+ g = parseInt(hex.slice(2, 4), 16);
21
+ b = parseInt(hex.slice(4, 6), 16);
22
+ a = hex.length === 8 ? Math.round(parseInt(hex.slice(6, 8), 16) / 255 * 100) / 100 : 1;
23
+ } else if (hex.length === 3) {
24
+ r = parseInt(hex[0] + hex[0], 16);
25
+ g = parseInt(hex[1] + hex[1], 16);
26
+ b = parseInt(hex[2] + hex[2], 16);
27
+ } else {
28
+ throw new Error('Invalid HEX color.');
29
+ }
30
+ return {
31
+ r,
32
+ g,
33
+ b,
34
+ a
35
+ };
36
+ } catch (error) {
37
+ console.error(error.message);
38
+ return hexToRgba(defaultColor);
27
39
  }
28
- return {
29
- r,
30
- g,
31
- b,
32
- a
33
- };
34
40
  };
35
41
  exports.hexToRgba = hexToRgba;
36
42
  const rgbaToHex = function (color) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtable-ui-component",
3
- "version": "5.1.1-alpha.1",
3
+ "version": "5.1.2",
4
4
  "main": "./lib/index.js",
5
5
  "dependencies": {
6
6
  "@seafile/react-image-lightbox": "2.0.5",