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,YACtB,KAAK,KAAK,EAAU,+BACpB,KAGF,EAAU,UAAU,SAAS,IAC3B,EAAM,EAAI,QAAQ,IAAI,OAAO,GAAG,cAAqB,KAAM,IAC3D,EAAM,GAAG,MAAY,EAAS,QAAc,KAAO,IAGrD,EAAM,UAAU,GAEZ,GACF,GAAG,cAAc,EAAgB,GACjC,QAAQ,IACN,gDAAgD,MAGlD,QAAQ,IAAI,gCAEd,SAAW,EACJ,QACT,CAAE,MAAO,GAEP,OADA,QAAQ,IAAI,QAAS,GACd,EACT,CACF,CAWA,SAAS,UAAW,GAwElB,OADA,GAbA,GAhBA,GAjBA,GAvBA,EAAM,EACH,QAAQ,2BAA4B,IACpC,QAAQ,sBAAuB,KAqBxB,QAAQ,mBAAoB,MAiB5B,QAAQ,iBAAkB,OAgB1B,QAAQ,kBAAmB,MAa3B,QAAQ,kBAAmB,MAEvC,CAuBA,SAAS,YAAa,EAAU,GAC9B,MAAM,EAAc,GAAG,aAAa,GAAU,WACxC,EAAY,KAAK,QAAQ,GAC/B,OAAO,EACJ,MAAM,MACN,KAAK,IACJ,GAAI,EAAK,WAAW,WAAY,CAC9B,IAAI,EAAa,EAAK,MAAM,6BAA6B,GACpD,EAAW,SAAS,WACvB,GAAc,SAEhB,IAAI,EAAU,KAAK,KAAK,EAAW,GAKnC,OAJI,EAAW,WAAW,OACxB,EAAa,EAAW,QAAQ,IAAK,IACrC,EAAU,KAAK,KAAK,EAAiB,KAAK,MAErC,YAAY,EAAS,EAC9B,CACA,OAAO,CAAI,IAEZ,KAAK,KACV,CA9HA,OAAO,QAAU,CACf,4BACA,0BACA,wBACA,wBACA,oBACA,kBAAmB","file":"/npm/@foundbyte/antd-theme-generator@1.2.12/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@foundbyte/antd-theme-generator@1.2.12/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const fs = require('fs');\nconst path = require('path');\nconst glob = require('glob');\nconst postcss = require('postcss');\nconst less = require('less');\nconst hash = require('hash.js');\nconst bundle = require('less-bundle-promise');\nconst NpmImportPlugin = require('less-plugin-npm-import');\nconst stripCssComments = require('strip-css-comments');\n\nlet hashCache = '';\nlet cssCache = '';\n\nconst COLOR_FUNCTIONS = [\n  'color',\n  'lighten',\n  'darken',\n  'saturate',\n  'desaturate',\n  'fadein',\n  'fadeout',\n  'fade',\n  'spin',\n  'mix',\n  'hsv',\n  'tint',\n  'shade',\n  'greyscale',\n  'multiply',\n  'contrast',\n  'screen',\n  'overlay'\n];\n\nconst defaultColorRegexArray = COLOR_FUNCTIONS.map(\n  (name) => new RegExp(`${name}\\(.*\\)`)\n);\ndefaultColorRegexArray.matches = (color) => {\n  return defaultColorRegexArray.reduce((prev, regex) => {\n    return prev || regex.test(color);\n  }, false);\n};\n\n/*\n  Generated random hex color code\n  e.g. #fe12ee\n*/\nfunction randomColor () {\n  return '#' + (0x1000000 + Math.random() * 0xffffff).toString(16).substr(1, 6);\n}\n\n/*\n  Recursively get the color code assigned to a variable e.g.\n  @primary-color: #1890ff;\n  @link-color: @primary-color;\n\n  @link-color -> @primary-color ->  #1890ff\n  Which means\n  @link-color: #1890ff\n*/\nfunction getColor (varName, mappings) {\n  const color = mappings[varName];\n  if (color in mappings) {\n    return getColor(color, mappings);\n  } else {\n    return color;\n  }\n}\n/*\n  Read following files and generate color variables and color codes mapping\n    - Ant design color.less, themes/default.less\n    - Your own variables.less\n  It will generate map like this\n  {\n    '@primary-color': '#00375B',\n    '@info-color': '#1890ff',\n    '@success-color': '#52c41a',\n    '@error-color': '#f5222d',\n    '@normal-color': '#d9d9d9',\n    '@primary-6': '#1890ff',\n    '@heading-color': '#fa8c16',\n    '@text-color': '#cccccc',\n    ....\n  }\n*/\nfunction generateColorMap (content, customColorRegexArray = []) {\n  return content\n    .split('\\n')\n    .filter((line) => line.startsWith('@') && line.indexOf(':') > -1)\n    .reduce((prev, next) => {\n      try {\n        const matches = next.match(\n          /(?=\\S*['-])([@a-zA-Z0-9'-]+).*:[ ]{1,}(.*);/\n        );\n        if (!matches) {\n          return prev;\n        }\n        let [, varName, color] = matches;\n        if (color && color.startsWith('@')) {\n          color = getColor(color, prev);\n          if (!isValidColor(color, customColorRegexArray)) return prev;\n          // if (defaultColorRegexArray.matches(color) && !color.includes('~')) {\n          //   color = `~'${color}'`;\n          // }\n          prev[varName] = color;\n        } else if (isValidColor(color, customColorRegexArray)) {\n          // if (defaultColorRegexArray.matches(color) && !color.includes('~')) {\n          //   color = `~'${color}'`;\n          // }\n          prev[varName] = color;\n        }\n        return prev;\n      } catch (e) {\n        console.log('e', e);\n        return prev;\n      }\n    }, {});\n}\n\n/*\n This plugin will remove all css rules except those are related to colors\n e.g.\n Input:\n .body {\n    font-family: 'Lato';\n    background: #cccccc;\n    color: #000;\n    padding: 0;\n    pargin: 0\n }\n\n Output:\n  .body {\n    background: #cccccc;\n    color: #000;\n }\n*/\nconst reducePlugin = postcss.plugin('reducePlugin', () => {\n  const cleanRule = (rule) => {\n    if (rule.selector.startsWith('.main-color .palatte-')) {\n      rule.remove();\n      return;\n    }\n\n    let removeRule = true;\n    rule.walkDecls((decl) => {\n      let matched = false;\n      if (String(decl.value).match(/url\\(.*\\)/g)) {\n        decl.remove();\n        matched = true;\n      }\n\n      // Removing transparent adds Link Button border color\n      // https://github.com/mzohaibqc/antd-theme-generator/issues/64\n      // if (!matched && decl.value === 'transparent') {\n      //   decl.remove();\n      //   matched = true;\n      // }\n      /*\n      this block causing https://github.com/ant-design/ant-design/issues/24777\n      if (decl.prop !== 'background' && decl.prop.includes('background') && !decl.prop.match(/^background-(.*)color$/ig)) {\n        decl.remove();\n        matched = true;\n      }\n      if (decl.prop !== 'border' && decl.prop.includes('border') && !decl.prop.match(/^border-(.*)color$/ig)) {\n        decl.remove();\n        matched = true;\n      }\n      if (['transparent', 'inherit', 'none', '0'].includes(decl.value)) {\n        decl.remove();\n        matched = true;\n      }\n      */\n      if (\n        !decl.prop.includes('color') &&\n        !decl.prop.includes('background') &&\n        !decl.prop.includes('border') &&\n        !decl.prop.includes('box-shadow') &&\n        !decl.prop.includes('stroke') &&\n        !decl.prop.includes('fill') &&\n        !Number.isNaN(decl.value)\n      ) {\n        // if (!matched) decl.remove();\n        decl.remove();\n      } else {\n        removeRule = matched ? removeRule : false;\n      }\n    });\n    if (removeRule) {\n      rule.remove();\n    }\n  };\n  return (css) => {\n    css.walkAtRules((atRule) => {\n      atRule.remove();\n    });\n\n    css.walkRules(cleanRule);\n\n    css.walkComments((c) => c.remove());\n  };\n});\n\nfunction getMatches (string, regex) {\n  const matches = {};\n  let match;\n  while ((match = regex.exec(string))) {\n    if (match[2].startsWith('rgba') || match[2].startsWith('#')) {\n      matches[`@${match[1]}`] = match[2];\n    }\n  }\n  return matches;\n}\n\n/*\n  This function takes less input as string and compiles into css.\n*/\nfunction render (text, paths) {\n  return less.render(text, {\n    paths: paths,\n    javascriptEnabled: true,\n    plugins: [new NpmImportPlugin({ prefix: '~' })]\n  });\n}\n\n/*\n  This funtion reads a less file and create an object with keys as variable names\n  and values as variables respective values. e.g.\n  //variabables.less\n    @primary-color : #1890ff;\n    @heading-color : #fa8c16;\n    @text-color : #cccccc;\n\n    to\n\n    {\n      '@primary-color' : '#1890ff',\n      '@heading-color' : '#fa8c16',\n      '@text-color' : '#cccccc'\n    }\n\n*/\nfunction getLessVars (filtPath) {\n  const sheet = fs.readFileSync(filtPath).toString();\n  const lessVars = {};\n  const matches = sheet.match(/@(.*:[^;]*)/g) || [];\n\n  matches.forEach((variable) => {\n    const definition = variable.split(/:\\s*/);\n    const varName = definition[0].replace(/['\"]+/g, '').trim();\n    lessVars[varName] = definition.splice(1).join(':');\n  });\n  return lessVars;\n}\n\n/*\n  This function take primary color palette name and returns @primary-color dependent value\n  .e.g\n  Input: @primary-1\n  Output: color(~`colorPalette(\"@{primary-color}\", ' 1 ')`)\n*/\nfunction getShade (varName) {\n  let [, className, number] = varName.match(/(.*)-(\\d)/);\n  if (/primary-\\d/.test(varName)) className = '@primary-color';\n  return (\n    'color(~`colorPalette(\"@{' +\n    className.replace('@', '') +\n    '}\", ' +\n    number +\n    ')`)'\n  );\n}\n\n/*\n  This function takes color string as input and return true if string is a valid color otherwise returns false.\n  e.g.\n  isValidColor('#ffffff'); //true\n  isValidColor('#fff'); //true\n  isValidColor('rgba(0, 0, 0, 0.5)'); //true\n  isValidColor('20px'); //false\n*/\nfunction isValidColor (color, customColorRegexArray = []) {\n  if (color && color.includes('rgb')) return true;\n  if (!color || color.match(/px/g)) return false;\n  if (color.match(/colorPalette|fade/g)) return true;\n  if (color.charAt(0) === '#') {\n    color = color.substring(1);\n    return (\n      [3, 4, 6, 8].indexOf(color.length) > -1 && !isNaN(parseInt(color, 16))\n    );\n  }\n  // eslint-disable-next-line\n  const isColor =\n    /^(rgb|hsl|hsv)a?\\((\\d+%?(deg|rad|grad|turn)?[,\\s]+){2,3}[\\s\\/]*[\\d\\.]+%?\\)$/i.test(\n      color\n    );\n  if (isColor) return true;\n  if (customColorRegexArray.length > 0) {\n    return customColorRegexArray.reduce((prev, regex) => {\n      return prev || regex.test(color);\n    }, false);\n  }\n  return false;\n}\n\nasync function compileAllLessFilesToCss (\n  stylesDir,\n  antdStylesDir,\n  varMap = {},\n  varPath,\n  rootEntryName = 'default'\n) {\n  /*\n    Get all less files path in styles directory\n    and then compile all to css and join\n  */\n  const stylesDirs = [].concat(stylesDir);\n  let styles = [];\n  stylesDirs.forEach((s) => {\n    styles = styles.concat(glob.sync(path.join(s, './**/*.less')));\n  });\n  const csss = await Promise.all(\n    styles.map((filePath) => {\n      let fileContent = fs.readFileSync(filePath).toString();\n      // Removed imports to avoid duplicate styles due to reading file separately as well as part of parent file (which is importing)\n      // if (avoidDuplicates) fileContent = fileContent.replace(/@import\\ [\"'](.*)[\"'];/g, '\\n');\n      const r = /@import [\"'](.*)[\"'];/g;\n      const directory = path.dirname(filePath);\n      fileContent = fileContent.replace(\n        r,\n        function (match, importPath, index, content) {\n          if (!importPath.endsWith('.less')) {\n            importPath += '.less';\n          }\n          // this change is for dynamic theme file added in antd after 4.15.x\n          if (importPath.includes('@{root-entry-name}')) {\n            importPath = importPath.replace(\n              '@{root-entry-name}',\n              rootEntryName\n            );\n          } else {\n            return '';\n          }\n          const newPath = path.join(directory, importPath);\n          // If imported path/file already exists in styles paths then replace import statement with empty line\n          if (styles.indexOf(newPath) === -1) {\n            return match;\n          } else {\n            return '';\n          }\n        }\n      );\n      Object.keys(varMap).forEach((varName) => {\n        fileContent = fileContent.replace(\n          new RegExp(`(:.*)(${varName})`, 'g'),\n          (match, group, a) => {\n            return match.replace(varName, varMap[varName]);\n          }\n        );\n      });\n      fileContent = `@import \"${varPath}\";\\n${fileContent}`;\n      // fileContent = `@import \"~antd/lib/style/themes/default.less\";\\n@import \"${varPath}\";\\n${fileContent}`;\n      return less\n        .render(fileContent, {\n          paths: [antdStylesDir].concat(stylesDir),\n          filename: path.resolve(filePath),\n          javascriptEnabled: true,\n          plugins: [new NpmImportPlugin({ prefix: '~' })]\n        })\n        .then((res) => {\n          return res;\n        })\n        .catch((e) => {\n          console.error(`Error occurred compiling file ${filePath}`);\n          console.error('Error', e);\n          return '\\n';\n        });\n    })\n  );\n  const hashes = {};\n\n  return csss\n    .map((c) => {\n      const css = stripCssComments(c.css || '', { preserve: false });\n      const hashCode = hash.sha256().update(css).digest('hex');\n      if (hashCode in hashes) {\n        return '';\n      } else {\n        hashes[hashCode] = hashCode;\n        return css;\n      }\n    })\n    .join('\\n');\n}\n\n/*\n  This is main function which call all other functions to generate color.less file which contins all color\n  related css rules based on Ant Design styles and your own custom styles\n  By default color.less will be generated in /public directory\n*/\nasync function generateTheme ({\n  antDir,\n  antdStylesDir,\n  stylesDir,\n  varFile,\n  outputFilePath,\n  themeVariables = ['@primary-color'],\n  customColorRegexArray = [],\n  rootEntryName = 'default'\n}) {\n  try {\n    const antdPath = antdStylesDir || path.join(antDir, 'lib');\n    const nodeModulesPath = path.join(\n      antDir.slice(0, antDir.indexOf('node_modules')),\n      './node_modules'\n    );\n    /*\n      stylesDir can be array or string\n    */\n    const stylesDirs = [].concat(stylesDir);\n    let styles = [];\n    stylesDirs.forEach((s) => {\n      styles = styles.concat(glob.sync(path.join(s, './**/*.less')));\n    });\n\n    let antdStylesFile;\n    if (rootEntryName === 'default') {\n      antdStylesFile = path.join(antDir, './dist/antd.less');\n    } else {\n      antdStylesFile = path.join(antDir, `./dist/antd.${rootEntryName}.less`);\n    }\n    /*\n      You own custom styles (Change according to your project structure)\n\n      - stylesDir - styles directory containing all less files\n      - varFile - variable file containing ant design specific and your own custom variables\n    */\n    varFile =\n      varFile || path.join(antdPath, `./style/themes/${rootEntryName}.less`);\n\n    let content = '';\n    styles.forEach((filePath) => {\n      if (filePath.endsWith('themes/index.less')) {\n        const fileContent = fs.readFileSync(filePath).toString();\n        content += fileContent.replace('@{root-entry-name}', rootEntryName);\n      } else {\n        content += fs.readFileSync(filePath).toString();\n      }\n    });\n\n    const hashCode = hash.sha256().update(content).digest('hex');\n    if (hashCode === hashCache) {\n      return cssCache;\n    }\n    hashCache = hashCode;\n    let themeCompiledVars = {};\n    let themeVars = themeVariables || ['@primary-color'];\n    const lessPaths = [path.join(antdPath, './style')].concat(stylesDir);\n\n    const randomColors = {};\n    const randomColorsVars = {};\n    /*\n    Ant Design Specific Files (Change according to your project structure)\n    You can even use different less based css framework and create color.less for  that\n\n    - antDir - ant design installation path\n    - entry - Ant Design less main file / entry file\n    - styles - Ant Design less styles for each component\n\n    1. Bundle all variables into one file\n    2. process vars and create a color name, color value key value map\n    3. Get variables which are part of theme\n    4.\n  */\n\n    const varFileContent = combineLess(varFile, nodeModulesPath);\n    let antdLess = await bundle({\n      src: antdStylesFile,\n      rootVars: { 'root-entry-name': rootEntryName }\n    });\n\n    customColorRegexArray = [\n      ...customColorRegexArray,\n      ...defaultColorRegexArray\n    ];\n    const mappings = Object.assign(\n      generateColorMap(varFileContent, customColorRegexArray),\n      getLessVars(varFile)\n    );\n\n    let css = '';\n    const PRIMARY_RANDOM_COLOR = '#123456';\n    themeVars = themeVars.filter(\n      (name) => name in mappings && !name.match(/(.*)-(\\d)/)\n    );\n    themeVars.forEach((varName) => {\n      let color = randomColor();\n      if (varName === '@primary-color') {\n        color = PRIMARY_RANDOM_COLOR;\n      } else {\n        while (\n          (randomColorsVars[color] && color === PRIMARY_RANDOM_COLOR) ||\n          color === '#000000' ||\n          color === '#ffffff'\n        ) {\n          color = randomColor();\n        }\n      }\n      randomColors[varName] = color;\n      randomColorsVars[color] = varName;\n      css = `.${varName.replace('@', '')} { color: ${color}; }\\n ${css}`;\n    });\n    const colorFuncMap = {};\n    let varsContent = '';\n    themeVars.forEach((varName) => {\n      [1, 2, 3, 4, 5, 7, 8, 9, 10].forEach((key) => {\n        const name =\n          varName === '@primary-color'\n            ? `@primary-${key}`\n            : `${varName}-${key}`;\n        css = `.${name.replace('@', '')} { color: ${getShade(\n          name\n        )}; }\\n ${css}`;\n      });\n      varsContent += `${varName}: ${randomColors[varName]};\\n`;\n    });\n\n    // This is to compile colors\n    // Put colors.less content first,\n    // then add random color variables to override the variables values for given theme variables with random colors\n    // Then add css containinf color variable classes\n    const colorFileContent = combineLess(\n      path.join(antdPath, './style/color/colors.less'),\n      nodeModulesPath\n    );\n    css = `${colorFileContent}\\n${varsContent}\\n${css}`;\n\n    let results = await render(css, lessPaths);\n    css = results.css;\n    css = css.replace(/(\\/.*\\/)/g, '');\n    const regex = /.(?=\\S*['-])([.a-zA-Z0-9'-]+)\\ {\\n {2}color: (.*);/g;\n    themeCompiledVars = getMatches(css, regex);\n    // Convert all custom user less files to css\n    const userCustomCss = await compileAllLessFilesToCss(\n      stylesDir,\n      antdStylesDir,\n      themeCompiledVars,\n      varFile,\n      rootEntryName\n    );\n    const fadeMap = {};\n    const fades = antdLess.match(/fade\\(.*\\)/g);\n    if (fades) {\n      fades.forEach((fade) => {\n        if (\n          !fade.startsWith('fade(@black') &&\n          !fade.startsWith('fade(@white') &&\n          !fade.startsWith('fade(#') &&\n          !fade.startsWith('fade(@color')\n        ) {\n          fadeMap[fade] = randomColor();\n        }\n      });\n    }\n    let varsCombined = '';\n    themeVars.forEach((varName) => {\n      let color;\n      if (/(.*)-(\\d)/.test(varName)) {\n        color = getShade(varName);\n        return;\n      } else {\n        color = themeCompiledVars[varName];\n      }\n      varsCombined = `${varsCombined}\\n${varName}: ${color};`;\n    });\n\n    COLOR_FUNCTIONS.slice(1).forEach((name) => {\n      antdLess = antdLess.replace(\n        new RegExp(`${name}\\\\((.*), \\\\d+%\\\\)`, 'g'),\n        (fullmatch, group) => {\n          if (mappings[group]) {\n            return `~'${fullmatch}'`;\n          }\n          return fullmatch;\n        }\n      );\n    });\n\n    antdLess = `${antdLess}\\n${varsCombined}`;\n    const { css: antCss } = await render(antdLess, [antdPath, antdStylesDir]);\n    const allCss = `${antCss}\\n${userCustomCss}`;\n    results = await postcss([reducePlugin]).process(allCss, {\n      from: antdStylesFile\n    });\n    css = results.css;\n\n    Object.keys(fadeMap).forEach((fade) => {\n      css = css.replace(new RegExp(fadeMap[fade], 'g'), fade);\n    });\n\n    Object.keys(themeCompiledVars).forEach((varName) => {\n      let color;\n      if (/(.*)-(\\d)/.test(varName)) {\n        color = themeCompiledVars[varName];\n        varName = getShade(varName);\n      } else {\n        color = themeCompiledVars[varName];\n      }\n      color = color.replace('(', '\\\\(').replace(')', '\\\\)');\n      css = css.replace(new RegExp(color, 'g'), varName);\n    });\n\n    Object.keys(colorFuncMap).forEach((varName) => {\n      const color = colorFuncMap[varName];\n      css = css.replace(new RegExp(color, 'g'), varName);\n    });\n    COLOR_FUNCTIONS.forEach((name) => {\n      css = css.replace(new RegExp(`~'(${name}\\(.*\\))'`), (a, b) => {\n        return b;\n      });\n    });\n    // Handle special cases\n    // https://github.com/mzohaibqc/antd-theme-webpack-plugin/issues/69\n    // 1. Replace fade(@primary-color, 20%) value i.e. rgba(18, 52, 86, 0.2)\n    css = css.replace(\n      new RegExp('rgba\\\\(18, 52, 86, 0.2\\\\)', 'g'),\n      'fade(@primary-color, 20%)'\n    );\n\n    css = css.replace(/@[\\w-_]+:\\s*.*;[\\/.]*/gm, '');\n\n    // This is to replace \\9 in Ant Design styles\n    css = css.replace(/\\\\9/g, '');\n    css = `${css.trim()}\\n${combineLess(\n      path.join(antdPath, './style/themes/default.less'),\n      nodeModulesPath\n    )}`;\n\n    themeVars.reverse().forEach((varName) => {\n      css = css.replace(new RegExp(`${varName}( *):(.*);`, 'g'), '');\n      css = `${varName}: ${mappings[varName]};\\n${css}\\n`;\n    });\n\n    css = minifyCss(css);\n\n    if (outputFilePath) {\n      fs.writeFileSync(outputFilePath, css);\n      console.log(\n        `🌈 Theme generated successfully. OutputFile: ${outputFilePath}`\n      );\n    } else {\n      console.log('Theme generated successfully');\n    }\n    cssCache = css;\n    return cssCache;\n  } catch (error) {\n    console.log('error', error);\n    return '';\n  }\n}\n\nmodule.exports = {\n  generateTheme,\n  isValidColor,\n  getLessVars,\n  randomColor,\n  minifyCss,\n  renderLessContent: render\n};\n\nfunction minifyCss (css) {\n  // Removed all comments and empty lines\n  css = css\n    .replace(/\\/\\*[\\s\\S]*?\\*\\/|\\/\\/.*/g, '')\n    .replace(/^\\s*$(?:\\r\\n?|\\n)/gm, '');\n\n  /*\n  Converts from\n\n    .abc,\n    .def {\n      color: red;\n      background: blue;\n      border: grey;\n    }\n\n    to\n\n    .abc,\n    .def {color: red;\n      background: blue;\n      border: grey;\n    }\n\n  */\n  css = css.replace(/\\{(\\r\\n?|\\n)\\s+/g, '{');\n\n  /*\n  Converts from\n\n  .abc,\n  .def {color: red;\n  }\n\n  to\n\n  .abc,\n  .def {color: red;\n    background: blue;\n    border: grey;}\n\n  */\n  css = css.replace(/;(\\r\\n?|\\n)\\}/g, ';}');\n\n  /*\n  Converts from\n\n  .abc,\n  .def {color: red;\n    background: blue;\n    border: grey;}\n\n  to\n\n  .abc,\n  .def {color: red;background: blue;border: grey;}\n\n  */\n  css = css.replace(/;(\\r\\n?|\\n)\\s+/g, ';');\n\n  /*\nConverts from\n\n.abc,\n.def {color: red;background: blue;border: grey;}\n\nto\n\n.abc, .def {color: red;background: blue;border: grey;}\n\n*/\n  css = css.replace(/,(\\r\\n?|\\n)[.]/g, ', .');\n  return css;\n}\n\n// const removeColorCodesPlugin = postcss.plugin('removeColorCodesPlugin', () => {\n//   const cleanRule = rule => {\n//     let removeRule = true;\n//     rule.walkDecls(decl => {\n//       if (\n//         !decl.value.includes('@')\n//       ) {\n//         decl.remove();\n//       } else {\n//         removeRule = false;\n//       }\n//     });\n//     if (removeRule) {\n//       rule.remove();\n//     }\n//   };\n//   return css => {\n//     css.walkRules(cleanRule);\n//   };\n// });\n\nfunction combineLess (filePath, nodeModulesPath) {\n  const fileContent = fs.readFileSync(filePath).toString();\n  const directory = path.dirname(filePath);\n  return fileContent\n    .split('\\n')\n    .map((line) => {\n      if (line.startsWith('@import')) {\n        let importPath = line.match(/@import[^'\"]*['\"](.*)['\"]/)[1];\n        if (!importPath.endsWith('.less')) {\n          importPath += '.less';\n        }\n        let newPath = path.join(directory, importPath);\n        if (importPath.startsWith('~')) {\n          importPath = importPath.replace('~', '');\n          newPath = path.join(nodeModulesPath, `./${importPath}`);\n        }\n        return combineLess(newPath, nodeModulesPath);\n      }\n      return line;\n    })\n    .join('\\n');\n}\n"]}