minima-rock 0.7.1 → 0.7.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.
- checksums.yaml +4 -4
- data/assets/js/color.js +25 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6887e2b068009d90dec8b055a9cb79e8229cfa7733c4672f7cce891999da0201
|
4
|
+
data.tar.gz: 496e9252e1a7f6bd0ad9112404901af19413b9e55db5b21988037f22ec751ace
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33e4ceca884224171d722e069fca831f49de4851312ac9e4ac3fba73c6af855a4f0a2d6e15556916bfcc10eb3a1ad87132a6a0c611f5bc18bd3c37ee1cd33e3d
|
7
|
+
data.tar.gz: e9229acd001783ae9a36ed17b51aed15f9f0fa8c5728775b1d1f59a6b18c04acfe8374c7f39aa355694571708da57d173f281dece835cad005a4233b31159308
|
data/assets/js/color.js
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* Refer to https://cp-algorithms.com/string/string-hashing.html
|
3
|
+
* @param {string} str
|
4
|
+
*/
|
5
|
+
function hash(str) {
|
6
|
+
const p = 31;
|
7
|
+
const m = 1e9 + 9;
|
8
|
+
let h = 0;
|
9
|
+
let pow = 1;
|
10
|
+
for (let i = 0; i < str.length; i++) {
|
11
|
+
const c = str.charCodeAt(i);
|
12
|
+
h = (h + (c - 'a'.charCodeAt(0) + 1) * pow) % m;
|
13
|
+
pow = (pow * p) % m;
|
14
|
+
}
|
15
|
+
return h;
|
16
|
+
}
|
17
|
+
|
1
18
|
function invertColor(hex, bw) {
|
2
19
|
if (hex.indexOf('#') === 0) {
|
3
20
|
hex = hex.slice(1);
|
@@ -25,6 +42,7 @@ function invertColor(hex, bw) {
|
|
25
42
|
// pad each with zeros and return
|
26
43
|
return "#" + padZero(r) + padZero(g) + padZero(b);
|
27
44
|
}
|
45
|
+
|
28
46
|
function padZero(str, len) {
|
29
47
|
len = len || 2;
|
30
48
|
var zeros = new Array(len).join('0');
|
@@ -36,11 +54,16 @@ function randomColor() {
|
|
36
54
|
return '#' + padZero(color, 6);
|
37
55
|
}
|
38
56
|
|
57
|
+
function hashColor(str) {
|
58
|
+
color = (hash(str) % 16777215).toString(16);
|
59
|
+
return '#' + padZero(color, 6);
|
60
|
+
}
|
61
|
+
|
39
62
|
function setInvertedColor(className) {
|
40
63
|
let elems = document.getElementsByClassName(className);
|
41
64
|
for (const elem of elems) {
|
42
|
-
const bgColor =
|
43
|
-
|
65
|
+
const bgColor = hashColor(elem.innerText);
|
66
|
+
const color = invertColor(bgColor, true);
|
44
67
|
elem.style['color'] = color;
|
45
68
|
elem.style['background-color'] = bgColor;
|
46
69
|
}
|