function StyleBuilder (state) { const { CustomArray, CustomArrayBasic, vNumCustomHeaders, vColorSchema, vColorText, vColorSchemaP, vLetterSize, colors } = state; let style = { fontSize: (14 + vLetterSize) + 'px' }; let hasComments = false; // vGlobalComment let commentColor; // vGlobalCommentColor let hasCustomFileStyle = false; // vGlobalComas, vGlobalComas2 function applyStandardAttributes (rowNumber) { const isEven = rowNumber % 2 === 0; style.backgroundColor = isEven ? vColorSchema : vColorSchemaP; style.color = vColorText; style.fontSize = (14 + vLetterSize) + 'px'; } function applyColor (color) { style.backgroundColor = color; commentColor = color; } const properties = { '': () => { hasComments = true; }, // text '': () => { style.fontWeight = 'bold'; }, '': () => { style.fontStyle = 'italic'; }, '': () => { style.fontStyle = 'oblique'; }, // background and comment color '': () => applyColor(colors.vColLibDark), '': () => applyColor(colors.vColLibNight), '': () => applyColor(colors.vColLibSoft), '': () => applyColor(colors.vColLibRed), '': () => applyColor(colors.vColLibOrange), '': () => applyColor(colors.vColLibViolete), '': () => applyColor(colors.vColLibBlue), '': () => applyColor(colors.vColLibGreen), // font color TODO: this is a color just like the others, but it applies to text instead.. any way to make it less weird? '': () => { style.color = 'white'; }, // font size '': () => { style.fontSize = (15 + vLetterSize) + 'px'; }, '': () => { style.fontSize = (14 + vLetterSize) + 'px'; }, '': () => { style.fontSize = (13 + vLetterSize) + 'px'; }, // text alignment '
': () => { style.textAlign = 'center'; } }; // TODO: need to improve this, it has way too many false positives function isCSSColor (property) { const isHexColor = property.substring(0, 1) == '#'; const isRGBColor = property.substring(0, 3).toUpperCase() == 'RGB'; return isHexColor || isRGBColor; } function applyProperty (property) { if (!property || property === 'none') { return; } if (isCSSColor(property)) { applyColor(property); return; } if (properties[property]) { properties[property](); } else { console.error(`Custom property ${property} does not exist`); // eslint-disable-line no-console } } function applyCustomStyle(customStyle) { style = { ...style, ...customStyle }; } function parseCustomFileStyle (columnText) { hasCustomFileStyle = true; for (let csvAttribute = 1; csvAttribute < vNumCustomHeaders; csvAttribute += 1) { let customAttribute = ''; if (CustomArrayBasic.indexOf(columnText) < 0) { customAttribute = 'none'; // TODO: is this used anywhere? } else { customAttribute = CustomArray[CustomArrayBasic.indexOf(columnText)][csvAttribute]; } applyProperty(customAttribute); } } return { getCommentColor: () => commentColor, getStyle: () => style, hasCustomFileStyle: () => hasCustomFileStyle, // to replace vGlobalComas and vGlobalComas2 hasFontSize: () => !!style.fontSize, // to vGlobalFontSize (vFontSize should just grab from style object or something) hasComments: () => hasComments, applyStandardAttributes, applyProperty, applyCustomStyle, parseCustomFileStyle }; } export default StyleBuilder;