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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/assets/js/color.js +25 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16bcacf16e1e6c0fe3c12b157c5b9f65ef1be0bde6c704b1615f3397352c285e
4
- data.tar.gz: 17f7ac280a162dc453d026f03aeceffd1ffe5ef16b3b8c62430bca1750d33542
3
+ metadata.gz: 6887e2b068009d90dec8b055a9cb79e8229cfa7733c4672f7cce891999da0201
4
+ data.tar.gz: 496e9252e1a7f6bd0ad9112404901af19413b9e55db5b21988037f22ec751ace
5
5
  SHA512:
6
- metadata.gz: 3af529f53ccf662ce414eafa8a3e36e4f86e1e404fafaeff453c29a1e5282121a84eb199bcea9a1d0f7336ac766a730b4225cf65ec22311dc745a64e78499af9
7
- data.tar.gz: f4c3c5bb1d4e2cb23b6d553bfc2f8ca9de6aff3359cfefb51cfff027568986d00e7cd97c09792173bec16375e80f64b6c1be7b0dc8c80fbd79d7bae4d2e523e6
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 = randomColor();
43
- let color = invertColor(bgColor, true);
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
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minima-rock
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Glovier