oolib 2.226.0 → 2.226.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.
@@ -23,3 +23,4 @@ export { decideLinkCompAndTarget } from "../../components/cards/utils/decideLink
23
23
  export { isExternalUrl } from "../../components/cards/utils/isExternalUrl";
24
24
  export { getPercentage } from "../getPercentage";
25
25
  export { getTotalCount } from "../getTotalCount";
26
+ export { getColorContrast } from "../color";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTotalCount = exports.getPercentage = exports.isExternalUrl = exports.decideLinkCompAndTarget = exports.stitchLink = exports.getDaysDiff = exports.useContainerQuery = exports.useScreenWidth = exports.testJSON = exports.useHandleClickOutside = exports.usePopOutOfOverflowHiddenParent = exports.useScroll = exports.isStringMatch = exports.sortData = exports.makeArrayFromLength = exports.toArray = exports.formatCamelCaseToSentenceCase = exports.formatTextToCamelCase = exports.injectHttps = exports.getBlockLabelProps = exports.getKeyCode = exports.getText = exports.deleteVal = exports.setVal = exports.getVal = void 0;
3
+ exports.getColorContrast = exports.getTotalCount = exports.getPercentage = exports.isExternalUrl = exports.decideLinkCompAndTarget = exports.stitchLink = exports.getDaysDiff = exports.useContainerQuery = exports.useScreenWidth = exports.testJSON = exports.useHandleClickOutside = exports.usePopOutOfOverflowHiddenParent = exports.useScroll = exports.isStringMatch = exports.sortData = exports.makeArrayFromLength = exports.toArray = exports.formatCamelCaseToSentenceCase = exports.formatTextToCamelCase = exports.injectHttps = exports.getBlockLabelProps = exports.getKeyCode = exports.getText = exports.deleteVal = exports.setVal = exports.getVal = void 0;
4
4
  //the holy setter, getter & deleter
5
5
  var getVal_1 = require("../getterSetterDeleter/getVal");
6
6
  Object.defineProperty(exports, "getVal", { enumerable: true, get: function () { return getVal_1.getVal; } });
@@ -56,3 +56,5 @@ var getPercentage_1 = require("../getPercentage");
56
56
  Object.defineProperty(exports, "getPercentage", { enumerable: true, get: function () { return getPercentage_1.getPercentage; } });
57
57
  var getTotalCount_1 = require("../getTotalCount");
58
58
  Object.defineProperty(exports, "getTotalCount", { enumerable: true, get: function () { return getTotalCount_1.getTotalCount; } });
59
+ var color_1 = require("../color");
60
+ Object.defineProperty(exports, "getColorContrast", { enumerable: true, get: function () { return color_1.getColorContrast; } });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Calculates the color contrast ratio between two colors according to WCAG 2.1
3
- * @param color1 - First color (any CSS color format: hex, rgb, oklch, oklab, color())
4
- * @param color2 - Second color (any CSS color format: hex, rgb, oklch, oklab, color())
3
+ * @param color1 - First color (CSS color format: hex, rgb, hsl, oklch, oklab, color())
4
+ * @param color2 - Second color (CSS color format: hex, rgb, hsl, oklch, oklab, color())
5
5
  * @returns Contrast ratio between 1 and 21
6
6
  */
7
7
  export declare const getColorContrast: (color1: string, color2: string) => number;
@@ -2,6 +2,74 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getColorContrast = void 0;
4
4
  var color_1 = require("@texel/color");
5
+ /**
6
+ * Parses an HSL color string and converts to RGB (0-1 range)
7
+ * @param hslString - HSL color string like "hsl(252, 83%, 56%)"
8
+ * @returns [r, g, b] array with values in 0-1 range, or null if invalid
9
+ */
10
+ var parseHSL = function (hslString) {
11
+ var match = hslString.match(/hsl\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)%\s*,\s*(\d+(?:\.\d+)?)%\s*\)/i);
12
+ if (!match)
13
+ return null;
14
+ var h = parseFloat(match[1]) / 360;
15
+ var s = parseFloat(match[2]) / 100;
16
+ var l = parseFloat(match[3]) / 100;
17
+ // HSL to RGB conversion
18
+ if (s === 0) {
19
+ return [l, l, l];
20
+ }
21
+ var hue2rgb = function (p, q, t) {
22
+ if (t < 0)
23
+ t += 1;
24
+ if (t > 1)
25
+ t -= 1;
26
+ if (t < 1 / 6)
27
+ return p + (q - p) * 6 * t;
28
+ if (t < 1 / 2)
29
+ return q;
30
+ if (t < 2 / 3)
31
+ return p + (q - p) * (2 / 3 - t) * 6;
32
+ return p;
33
+ };
34
+ var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
35
+ var p = 2 * l - q;
36
+ var r = hue2rgb(p, q, h + 1 / 3);
37
+ var g = hue2rgb(p, q, h);
38
+ var b = hue2rgb(p, q, h - 1 / 3);
39
+ return [r, g, b];
40
+ };
41
+ /**
42
+ * Parses a color string to RGB (0-1 range)
43
+ * Supports: hex, rgb(), hsl(), and formats supported by @texel/color
44
+ * @param colorString - CSS color string
45
+ * @returns [r, g, b] array with values in 0-1 range
46
+ */
47
+ var parseColor = function (colorString) {
48
+ var trimmed = colorString.trim().toLowerCase();
49
+ // Handle HSL format (not supported by @texel/color)
50
+ if (trimmed.startsWith("hsl(")) {
51
+ var rgb = parseHSL(trimmed);
52
+ if (rgb)
53
+ return rgb;
54
+ throw new Error("Invalid HSL color format: ".concat(colorString));
55
+ }
56
+ // Handle hex format
57
+ if (trimmed.startsWith("#") || /^[0-9a-f]{3,8}$/i.test(trimmed)) {
58
+ var hex = trimmed.startsWith("#") ? trimmed : "#".concat(trimmed);
59
+ var rgb = (0, color_1.hexToRGB)(hex);
60
+ return [rgb[0], rgb[1], rgb[2]];
61
+ }
62
+ // Try @texel/color parser for other formats (rgb, oklch, oklab, color())
63
+ try {
64
+ var rgb = (0, color_1.parse)(colorString, color_1.sRGB);
65
+ if (rgb)
66
+ return [rgb[0], rgb[1], rgb[2]];
67
+ }
68
+ catch (_a) {
69
+ // Fall through to error
70
+ }
71
+ throw new Error("Could not parse color string: ".concat(colorString));
72
+ };
5
73
  /**
6
74
  * Calculates the relative luminance of a color according to WCAG 2.1
7
75
  * @param r - Red component (0-1)
@@ -17,17 +85,13 @@ var getRelativeLuminance = function (r, g, b) {
17
85
  };
18
86
  /**
19
87
  * Calculates the color contrast ratio between two colors according to WCAG 2.1
20
- * @param color1 - First color (any CSS color format: hex, rgb, oklch, oklab, color())
21
- * @param color2 - Second color (any CSS color format: hex, rgb, oklch, oklab, color())
88
+ * @param color1 - First color (CSS color format: hex, rgb, hsl, oklch, oklab, color())
89
+ * @param color2 - Second color (CSS color format: hex, rgb, hsl, oklch, oklab, color())
22
90
  * @returns Contrast ratio between 1 and 21
23
91
  */
24
92
  var getColorContrast = function (color1, color2) {
25
- // Parse colors and convert to sRGB (returns [r, g, b] in 0-1 range)
26
- var rgb1 = (0, color_1.parse)(color1, color_1.sRGB);
27
- var rgb2 = (0, color_1.parse)(color2, color_1.sRGB);
28
- if (!rgb1 || !rgb2) {
29
- throw new Error("Invalid color format provided");
30
- }
93
+ var rgb1 = parseColor(color1);
94
+ var rgb2 = parseColor(color2);
31
95
  // Get luminance values (rgb values are in 0-1 range)
32
96
  var l1 = getRelativeLuminance(rgb1[0], rgb1[1], rgb1[2]);
33
97
  var l2 = getRelativeLuminance(rgb2[0], rgb2[1], rgb2[2]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oolib",
3
- "version": "2.226.0",
3
+ "version": "2.226.2",
4
4
  "description": " OKE Component Library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -75,6 +75,7 @@
75
75
  "typescript": "^5.4.3"
76
76
  },
77
77
  "peerDependencies": {
78
+ "@texel/color": "^1.1.10",
78
79
  "date-fns": "^2.0.0",
79
80
  "react": "^17.0.2 || ^18.0.0",
80
81
  "react-dom": "^17.0.2 || ^18.0.0",
@@ -96,7 +97,6 @@
96
97
  "@material/material-color-utilities": "^0.3.0",
97
98
  "@phosphor-icons/react": "^2.1.10",
98
99
  "@react-hook/resize-observer": "^1.2.6",
99
- "@texel/color": "^1.1.10",
100
100
  "babel-polyfill": "^6.26.0",
101
101
  "d3": "^7.8.5",
102
102
  "d3-collection": "^1.0.7",