diff --git a/js/framework.js b/js/framework.js index 07890e5..8859a61 100644 --- a/js/framework.js +++ b/js/framework.js @@ -1,9 +1,34 @@ const defaultFontSize = 16; -function calculateRem(valueInPixals){ +const calculateRem = function(valueInPixals){ valueInPixals = parseFloat(valueInPixals.replace('px', '')); return `${valueInPixals / defaultFontSize}rem`; -} +}; + +const lightenDarkenColor = function (col, amt) { + let usePound = false; + if (col[0] === "#") { + col = col.slice(1); + usePound = true; + } + let num = parseInt(col, 16); + let r = (num >> 16) + amt; + + if (r > 255) r = 255; + else if (r < 0) r = 0; + + let b = ((num >> 8) & 0x00FF) + amt; + + if (b > 255) b = 255; + else if (b < 0) b = 0; + + let g = (num & 0x0000FF) + amt; + + if (g > 255) g = 255; + else if (g < 0) g = 0; + + return (usePound ? "#" : "") + (g | (b << 8) | (r << 16)).toString(16); +}; const framework = { variables: { @@ -31,4 +56,4 @@ const framework = { } }; -export default framework; +export {framework, calculateRem, lightenDarkenColor}; diff --git a/processTemplates.js b/processTemplates.js index 611abe2..fe3e40b 100644 --- a/processTemplates.js +++ b/processTemplates.js @@ -1,7 +1,7 @@ 'use strict'; const fs = require('fs'); -import cssFramework from './js/framework'; //This is possible with the ESM lib +import {framework} from './js/framework'; //This is possible with the ESM lib function readInTemplate(fileName) { try { @@ -12,7 +12,7 @@ function readInTemplate(fileName) { } //Process Variables -const variables = cssFramework.variables; +const variables = framework.variables; let variableTmpl = readInTemplate("./templates/_variables.scss.tmpl"); for (let [key, value] of Object.entries(variables)) { variableTmpl = variableTmpl.replace(`#(${key})`, value); @@ -20,16 +20,16 @@ for (let [key, value] of Object.entries(variables)) { fs.writeFileSync('./scss/_variables.scss', variableTmpl); //Process Breakpoints and Spacers -const spacers = cssFramework.spacers; +const spacers = framework.spacers; let breakPointTmpl = readInTemplate("./templates/_breakpoints.scss.tmpl"); for (let [key, value] of Object.entries(spacers)) { breakPointTmpl = breakPointTmpl.replace(`#(${key})`, value); } -const gridBreakpoints = cssFramework.gridBreakpoints; +const gridBreakpoints = framework.gridBreakpoints; for (let [key, value] of Object.entries(gridBreakpoints)) { breakPointTmpl = breakPointTmpl.replace(`#(${key})`, value); } -const gridBreakpointsMax = cssFramework.gridBreakpointsMax; +const gridBreakpointsMax = framework.gridBreakpointsMax; for (let [key, value] of Object.entries(gridBreakpointsMax)) { breakPointTmpl = breakPointTmpl.replace(`#(${key})`, value); }