From ddca239668167b34157e6dfd2ab88e6b9774db7d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 5 Apr 2021 15:21:24 -0300 Subject: info card thumbnail & image link/color niceness --- common/common.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'common/common.js') diff --git a/common/common.js b/common/common.js index 56ee7b3..165e0f6 100644 --- a/common/common.js +++ b/common/common.js @@ -117,7 +117,26 @@ const C = { (artist.flashes ? artist.flashes.asContributor.length : 0) ), - getArtistCommentary: (artist, {justEverythingMan}) => justEverythingMan.filter(thing => thing.commentary && thing.commentary.replace(/<\/?b>/g, '').includes('' + artist.name + ':')) + getArtistCommentary: (artist, {justEverythingMan}) => justEverythingMan.filter(thing => thing.commentary && thing.commentary.replace(/<\/?b>/g, '').includes('' + artist.name + ':')), + + // Graciously stolen from https://stackoverflow.com/a/54071699! ::::) + // in: r,g,b in [0,1], out: h in [0,360) and s,l in [0,1] + rgb2hsl: (r,g,b) => { + let a=Math.max(r,g,b), n=a-Math.min(r,g,b), f=(1-Math.abs(a+a-n-1)); + let h= n && ((a==r) ? (g-b)/n : ((a==g) ? 2+(b-r)/n : 4+(r-g)/n)); + return [60*(h<0?h+6:h), f ? n/f : 0, (a+a-n)/2]; + }, + + getColors: primary => { + const [ r, g, b ] = primary.slice(1) + .match(/[0-9a-fA-F]{2,2}/g) + .slice(0, 3) + .map(val => parseInt(val, 16) / 255); + const [ h, s, l ] = C.rgb2hsl(r, g, b); + const dim = `hsl(${Math.round(h)}deg, ${Math.round(s * 50)}%, ${Math.round(l * 80)}%)`; + + return {primary, dim}; + } }; if (typeof module === 'object') { -- cgit 1.3.0-6-gf8a5