nhb-toolbox 3.4.5 → 3.4.6
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/colors/Color.d.ts +1 -1
- package/dist/colors/Color.d.ts.map +1 -1
- package/dist/colors/Color.js +14 -24
- package/package.json +1 -1
package/dist/colors/Color.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export declare class Color {
|
|
|
55
55
|
* @example
|
|
56
56
|
* const alphaColor = new Color("#ff000080"); // Color with 50% opacity
|
|
57
57
|
* const alpha75 = alphaColor.applyOpacity(75); // Change to 75% opacity
|
|
58
|
-
* console.log(alpha75.hex8); // #
|
|
58
|
+
* console.log(alpha75.hex8); // #FF0000BF
|
|
59
59
|
*/
|
|
60
60
|
applyOpacity(opacity: OpacityValue): SolidColors & AlphaColors;
|
|
61
61
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,KAAK;IACV,GAAG,EAAE,IAAI,CAAC;IACV,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IAElB,iEAAiE;IAChE,CAAC,MAAM,CAAC,QAAQ,CAAC;IASlB;;;;OAIG;gBACS,SAAS,CAAC,EAAE,SAAS;
|
|
1
|
+
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../src/colors/Color.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACX,WAAW,EACX,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,YAAY,EACZ,GAAG,EACH,IAAI,EACJ,WAAW,EACX,MAAM,SAAS,CAAC;AAKjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,KAAK;IACV,GAAG,EAAE,IAAI,CAAC;IACV,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IACX,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;IAElB,iEAAiE;IAChE,CAAC,MAAM,CAAC,QAAQ,CAAC;IASlB;;;;OAIG;gBACS,SAAS,CAAC,EAAE,SAAS;IA2CjC;;;;;;;;;;;;;;;;;OAiBG;IACH,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,WAAW,GAAG,WAAW;IAkB9D;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAIlD;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;OAKG;WACW,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,GAAG;IAIhD;;;;;OAKG;WACW,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,IAAI;IAMlD;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;CAuB7B"}
|
package/dist/colors/Color.js
CHANGED
|
@@ -2,7 +2,7 @@ import { convertColorCode } from './convert';
|
|
|
2
2
|
import { _convertOpacityToHex, _extractAlphaColorValues, _extractSolidColorValues, } from './helpers';
|
|
3
3
|
import { generateRandomHSLColor } from './random';
|
|
4
4
|
const hsl = generateRandomHSLColor();
|
|
5
|
-
const
|
|
5
|
+
const { hex, rgb } = convertColorCode(hsl);
|
|
6
6
|
/**
|
|
7
7
|
* * Class representing a color and its conversions among `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` and `HSLA` formats.
|
|
8
8
|
* * It has 1 instance method `applyOpacity()` to apply opacity to `Hex`, `Hex8` `RGB`, `RGBA`, `HSL` or `HSLA` color.
|
|
@@ -56,8 +56,8 @@ export class Color {
|
|
|
56
56
|
// Extract alpha color values (Hex8, RGBA, HSLA)
|
|
57
57
|
const rgbaValues = _extractAlphaColorValues(colors.rgba);
|
|
58
58
|
const hslaValues = _extractAlphaColorValues(colors.hsla);
|
|
59
|
-
this.hex = colors.hex8.slice(0, 7);
|
|
60
|
-
this.hex8 = colors.hex8;
|
|
59
|
+
this.hex = colors.hex8.toUpperCase().slice(0, 7);
|
|
60
|
+
this.hex8 = colors.hex8.toUpperCase();
|
|
61
61
|
this.rgb = `rgb(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]})`;
|
|
62
62
|
this.rgba = colors.rgba;
|
|
63
63
|
this.hsl = `hsl(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%)`;
|
|
@@ -67,8 +67,9 @@ export class Color {
|
|
|
67
67
|
// Extract solid color values (Hex, RGB, HSL)
|
|
68
68
|
const rgbValues = _extractSolidColorValues(colors.rgb);
|
|
69
69
|
const hslValues = _extractSolidColorValues(colors.hsl);
|
|
70
|
-
this.hex = colors.hex;
|
|
71
|
-
this.hex8 =
|
|
70
|
+
this.hex = colors.hex.toUpperCase();
|
|
71
|
+
this.hex8 =
|
|
72
|
+
`${colors.hex.toUpperCase()}${_convertOpacityToHex(100)}`;
|
|
72
73
|
this.rgb = colors.rgb;
|
|
73
74
|
this.rgba = `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, 1)`;
|
|
74
75
|
this.hsl = colors.hsl;
|
|
@@ -76,12 +77,13 @@ export class Color {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
else {
|
|
79
|
-
const rgbValues = _extractSolidColorValues(
|
|
80
|
+
const rgbValues = _extractSolidColorValues(rgb);
|
|
80
81
|
const hslValues = _extractSolidColorValues(hsl);
|
|
81
82
|
// Generate random colors
|
|
82
|
-
this.hex =
|
|
83
|
-
this.hex8 =
|
|
84
|
-
|
|
83
|
+
this.hex = hex.toUpperCase();
|
|
84
|
+
this.hex8 =
|
|
85
|
+
`${hex.toUpperCase()}${_convertOpacityToHex(100)}`;
|
|
86
|
+
this.rgb = rgb;
|
|
85
87
|
this.rgba = `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, 1)`;
|
|
86
88
|
this.hsl = hsl;
|
|
87
89
|
this.hsla = `hsla(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%, 1)`;
|
|
@@ -103,29 +105,17 @@ export class Color {
|
|
|
103
105
|
* @example
|
|
104
106
|
* const alphaColor = new Color("#ff000080"); // Color with 50% opacity
|
|
105
107
|
* const alpha75 = alphaColor.applyOpacity(75); // Change to 75% opacity
|
|
106
|
-
* console.log(alpha75.hex8); // #
|
|
108
|
+
* console.log(alpha75.hex8); // #FF0000BF
|
|
107
109
|
*/
|
|
108
110
|
applyOpacity(opacity) {
|
|
109
111
|
const validOpacity = Math.min(100, Math.max(0, opacity));
|
|
110
112
|
const alphaHex = _convertOpacityToHex(opacity);
|
|
111
113
|
const alphaDecimal = validOpacity / 100;
|
|
112
|
-
if (Color.isHex8(this.hex8)) {
|
|
113
|
-
const rgbaValues = _extractAlphaColorValues(this.rgba);
|
|
114
|
-
const hslaValues = _extractAlphaColorValues(this.hsla);
|
|
115
|
-
return {
|
|
116
|
-
hex: this.hex8.slice(0, 7),
|
|
117
|
-
hex8: `${this.hex8.slice(0, 7)}${alphaHex}`,
|
|
118
|
-
rgb: `rgb(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]})`,
|
|
119
|
-
rgba: `rgba(${rgbaValues[0]}, ${rgbaValues[1]}, ${rgbaValues[2]}, ${alphaDecimal})`,
|
|
120
|
-
hsl: `hsl(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%)`,
|
|
121
|
-
hsla: `hsla(${hslaValues[0]}, ${hslaValues[1]}%, ${hslaValues[2]}%, ${alphaDecimal})`,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
114
|
const rgbValues = _extractSolidColorValues(this.rgb);
|
|
125
115
|
const hslValues = _extractSolidColorValues(this.hsl);
|
|
126
116
|
return {
|
|
127
|
-
hex: this.hex.slice(0, 7),
|
|
128
|
-
hex8: `${this.hex.slice(0, 7)}${alphaHex}
|
|
117
|
+
hex: this.hex.slice(0, 7).toUpperCase(),
|
|
118
|
+
hex8: `${this.hex.slice(0, 7)}${alphaHex}`.toUpperCase(),
|
|
129
119
|
rgb: `rgb(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]})`,
|
|
130
120
|
rgba: `rgba(${rgbValues[0]}, ${rgbValues[1]}, ${rgbValues[2]}, ${alphaDecimal})`,
|
|
131
121
|
hsl: `hsl(${hslValues[0]}, ${hslValues[1]}%, ${hslValues[2]}%)`,
|
package/package.json
CHANGED