This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stringToColor (text, { saturation = 64, lightness = 40, alpha = 100 } = {}) { | |
let hue = [...text].reduce((a, c) => c.charCodeAt(0) + ((a << 5) - a), 0) % 360 | |
return `hsl(${hue} ${saturation}% ${lightness}% / ${alpha / 100})` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function colorFromString ( | |
text, | |
saturation = 90, | |
lightness = 50, | |
alpha = 100 | |
) { | |
let hash = 0 | |
for (let i = 0; i < text.length; i++) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function observeMutations (element, callback, options) { | |
const observer = new MutationObserver(mutations => | |
mutations.forEach(m => callback(m)) | |
) | |
observer.observe(element, Object.assign({ | |
childList: true, | |
attributes: true, | |
attributeOldValue: true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tagged from 'tagged.js' | |
const css = tagged(function (str) { | |
const css = new CSSStyleSheet() | |
return css.replace(str.trim()) | |
}) | |
export default css |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getSiblings = e => Array.from(e.parentNode.children).filter(sib => sib !== e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const flatten = (array, depth = Infinity) => array.flat(depth) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deburr = str => str.normalize('NFD').replace(/\p{Diacritic}/gu, '') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const chunk = (array, size) => array.map( | |
(_, i) => i % size === 0 ? array.slice(i, i + size) : null | |
).filter(Boolean) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFetch(url, params = {}) { | |
const queryString = Object.entries(params).map( | |
param => `${param[0]}=${param[1]}` | |
).join('&') | |
return fetch(`${url}?${queryString}`, { | |
method: "GET", | |
headers: { "Content-Type": "application/json" } | |
}).then(res => res.json()) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Color contrast v2. | |
// -------------------- | |
@function _color-contrast-test($color, $threshold) { | |
$r: red($color); | |
$g: green($color); | |
$b: blue($color); | |
$yiq: (($r * 299) + ($g * 587) + ($b * 114)) / 1000; |
NewerOlder