forked from hihayk/shaper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.js
51 lines (45 loc) · 1.54 KB
/
utilities.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export const randomNumber = (min, max, full) => {
const num = Math.random() * (max - min) + min
let rand = min + Math.random() * (max - min);
if (full === 'full') {
return Math.round(rand)
}
return Math.round((num + Number.EPSILON) * 100) / 100
}
export const setProperty = (property, value) => {
document.documentElement.style.setProperty(`--${property}`, value);
}
export const getProperty = (property) => {
getComputedStyle(document.documentElement).getPropertyValue(`--${property}`);
}
export const fonts = [
'system-ui, sans-serif',
'IBM Plex Sans',
'Futura, sans-serif',
'Roboto Mono',
'Nunito',
'Helvetica, sans-serif',
'Merriweather',
'Work Sans',
]
const buttonIsRound = [true, false, false, false]
export const getRandomObject = () => {
const randomFontsPosition = randomNumber(0, fonts.length-1, 'full')
return {
fontFamily: fonts[randomFontsPosition],
textSizeIncrement: randomNumber(1.2, 1.4),
baseTextSize: randomNumber(0.875, 1.1),
textFrameRatio: randomNumber(1.2, 3),
textFrameY: randomNumber(0.4, 1),
unit: randomNumber(0.4, 0.8),
spaceIncrement: randomNumber(1.5, 1.8),
accentHue: randomNumber(0, 360, 'full'),
accentSaturation: randomNumber(0, 100, 'full'),
accentLightness: randomNumber(30, 60, 'full'),
greySaturation: randomNumber(0, 10, 'full'),
radius: randomNumber(0, 0.4),
fieldBorderWidth: randomNumber(1, 3, 'full'),
buttonRound: buttonIsRound[randomNumber(0, 3, 'full')],
}
}
export const numberToUnit = (number, unit) => `${number}${unit}`