@cd-z/epub-constructor
Version:
This is a react library that creates an epub structure. This library only provides the file structure. To get a valid epub file it is needed to to create files from the provided data and compress them to a epub file.
43 lines (42 loc) • 1.27 kB
JavaScript
/**
* Generates a CSS string based on the provided style object.
* If the style object is a string, it is returned as is.
* The style object is merged with a default style object.
*
* @param style - The style object to generate CSS from.
* @returns The CSS string representing the merged style object.
*/
export function createStyle(style) {
if (typeof style === 'string') {
return style;
}
if (!style) {
return ('body {\n' +
' font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;\n' +
' font-size: 1.125em;\n' +
' line-height: 1.6em;\n' +
' color: #000;\n' +
'}\n' +
'h1, h2, h3, h4, h5, h6 {\n' +
' line-height: 1em;\n' +
'}\n' +
'h1 {\n' +
' font-size: 3em;\n' +
'}\n' +
'h2 {\n' +
' font-size: 2.5em;\n' +
'}\n');
}
// Creating well formated css
var result = '';
Object.keys(style).forEach(x => {
const key = x;
var item = x + ' {';
Object.keys(style[key]).forEach(a => {
item += `\n ${a}: ${style[key][a]};`;
});
item += '\n}\n';
result += item;
});
return result;
}