2016-12-06 13:50:24 +02:00
|
|
|
const calc = require('reduce-css-calc');
|
2016-12-09 16:56:34 +02:00
|
|
|
const randomNatural = require('random-natural');
|
|
|
|
|
|
|
|
// from https://github.com/styled-components/styled-components/blob/065001c725744629c7870240e4a955b924ef5337/src/utils/generateAlphabeticName.js
|
2016-12-09 17:33:24 +02:00
|
|
|
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('');
|
2016-12-09 16:56:34 +02:00
|
|
|
const rndId = (_code) => {
|
|
|
|
const code = !_code ? randomNatural({
|
|
|
|
min: 1000000000
|
|
|
|
}) : _code;
|
|
|
|
|
|
|
|
const lastDigit = chars[code % chars.length];
|
|
|
|
return code > chars.length
|
|
|
|
? `${rndId(Math.floor(code / chars.length))}${lastDigit}`
|
|
|
|
: lastDigit;
|
|
|
|
};
|
2016-12-06 13:50:24 +02:00
|
|
|
|
2017-01-10 14:11:03 +02:00
|
|
|
const generateFonts = (fontFamilies, fontFilenames) => {
|
|
|
|
const pathToFont = '../../shared/fonts/';
|
|
|
|
let fontCSS = '';
|
|
|
|
|
|
|
|
fontFamilies.forEach( (fontFamily, i) => {
|
|
|
|
fontCSS += `
|
|
|
|
@font-face {
|
|
|
|
font-family: ${fontFamily};
|
|
|
|
src: url(${pathToFont}${fontFilenames[i]}.eot);
|
|
|
|
src: url(${pathToFont}${fontFilenames[i]}.eot?#iefix)
|
|
|
|
format('embedded-opentype');
|
|
|
|
src: url(${pathToFont}${fontFilenames[i]}.woff)
|
|
|
|
format('woff');
|
|
|
|
src: url(${pathToFont}${fontFilenames[i]}.woff2)
|
|
|
|
format('woff2');
|
|
|
|
src: url(${pathToFont}${fontFilenames[i]}.ttf)
|
|
|
|
format('truetype');
|
|
|
|
src: url(${pathToFont}${fontFilenames[i]}.svg#${fontFamily})
|
|
|
|
format('svg');
|
|
|
|
font-weight: normal;
|
|
|
|
font-style: normal;
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
});
|
|
|
|
return fontCSS;
|
|
|
|
};
|
|
|
|
|
2016-10-28 17:14:35 +03:00
|
|
|
module.exports = {
|
2016-12-09 16:56:34 +02:00
|
|
|
remcalc: (values) => {
|
2016-12-08 14:08:04 +02:00
|
|
|
values = values.toString().replace('px', '').split(' ');
|
2016-10-28 17:14:35 +03:00
|
|
|
|
|
|
|
let outputRems = '';
|
|
|
|
const base = 16;
|
|
|
|
|
|
|
|
values.forEach( (value, i) => {
|
|
|
|
const remValue = value / base;
|
|
|
|
outputRems += i === 0 ? `${remValue}rem` : ` ${remValue}rem`;
|
|
|
|
});
|
|
|
|
|
|
|
|
return outputRems;
|
2016-12-06 13:50:24 +02:00
|
|
|
},
|
2016-12-09 16:56:34 +02:00
|
|
|
calc: (str) => calc(`calc(${str})`),
|
2017-01-10 14:11:03 +02:00
|
|
|
rndId,
|
|
|
|
generateFonts
|
2016-10-28 17:14:35 +03:00
|
|
|
};
|