@colisweb/rescript-toolkit 5.43.4 → 5.44.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/package.json +1 -1
- package/src/utils/Toolkit__Utils.res +46 -0
package/package.json
CHANGED
|
@@ -47,3 +47,49 @@ let decodeEnumFromString = (type enum, str: string, enum: module(Enum with type
|
|
|
47
47
|
| Error(_) => None
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
+
|
|
51
|
+
%%private(
|
|
52
|
+
let hashString = %raw(`function hashString(str) {
|
|
53
|
+
let hash = 5381;
|
|
54
|
+
for (let i = 0; i < str.length; i++) {
|
|
55
|
+
hash = ((hash << 5) + hash) + str.charCodeAt(i); // hash * 33 + c
|
|
56
|
+
}
|
|
57
|
+
return hash >>> 0; // assurer un entier positif
|
|
58
|
+
}`)
|
|
59
|
+
|
|
60
|
+
let hsvToRgb = %raw(`function hsvToRgb(h, s, v) {
|
|
61
|
+
const c = v * s;
|
|
62
|
+
const hPrime = h / 60;
|
|
63
|
+
const x = c * (1 - Math.abs((hPrime % 2) - 1));
|
|
64
|
+
let r1, g1, b1;
|
|
65
|
+
|
|
66
|
+
if (hPrime < 1) {
|
|
67
|
+
r1 = c; g1 = x; b1 = 0;
|
|
68
|
+
} else if (hPrime < 2) {
|
|
69
|
+
r1 = x; g1 = c; b1 = 0;
|
|
70
|
+
} else if (hPrime < 3) {
|
|
71
|
+
r1 = 0; g1 = c; b1 = x;
|
|
72
|
+
} else if (hPrime < 4) {
|
|
73
|
+
r1 = 0; g1 = x; b1 = c;
|
|
74
|
+
} else if (hPrime < 5) {
|
|
75
|
+
r1 = x; g1 = 0; b1 = c;
|
|
76
|
+
} else {
|
|
77
|
+
r1 = c; g1 = 0; b1 = x;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const m = v - c;
|
|
81
|
+
const r = Math.round((r1 + m) * 255).toString(16).padStart(2, '0');
|
|
82
|
+
const g = Math.round((g1 + m) * 255).toString(16).padStart(2, '0');
|
|
83
|
+
const b = Math.round((b1 + m) * 255).toString(16).padStart(2, '0');
|
|
84
|
+
|
|
85
|
+
return [r, g, b];
|
|
86
|
+
}`)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
let makeRgbColor = id => {
|
|
90
|
+
let hash = hashString(id)
|
|
91
|
+
let hue = mod(hash * 997, 360)
|
|
92
|
+
let (r, g, b) = hsvToRgb(hue, 0.6, 0.85)
|
|
93
|
+
|
|
94
|
+
"#" ++ r ++ g ++ b
|
|
95
|
+
}
|