[
  {
    "path": ".editorconfig",
    "content": "# editorconfig.org\nroot = true\n\n[*]\nend_of_line = lf\ncharset = utf-8\ntrim_trailing_whitespace = true\ninsert_final_newline = true\nindent_style = space\nindent_size = 2\n\n[*.md]\ntrim_trailing_whitespace = false\n\n[Makefile]\nindent_style = tab\n"
  },
  {
    "path": ".eslintrc.yml",
    "content": "root: true\nextends: eslint:recommended\n\nparserOptions:\n  ecmaVersion: 5\n\nenv:\n  commonjs: true\n\nrules:\n  indent: [2, 2] # 2 spaces indentation\n  max-len: [2, 80, 2]\n  quotes: [2, \"double\"]\n  semi: [2, \"never\"]\n  no-multiple-empty-lines: [2, {\"max\": 1}]\n\n  brace-style: [2, \"stroustrup\"]\n  comma-dangle: [2, \"always-multiline\"]\n  comma-style: [2, \"last\"]\n  dot-location: [2, \"property\"]\n\n  one-var: [2, \"never\"]\n#  no-var: [2]\n  prefer-const: [2]\n  no-bitwise: [2]\n\n  object-curly-spacing: [2, \"never\"]\n  array-bracket-spacing: [2, \"never\"]\n  computed-property-spacing: [2, \"never\"]\n\n  space-unary-ops: [2, {\"words\": true, \"nonwords\": false}]\n  keyword-spacing: [2, {\"before\": true, \"after\": true}]\n  space-before-blocks: [2, \"always\"]\n  space-before-function-paren: [2, \"never\"]\n  space-in-parens: [2, \"never\"]\n  spaced-comment: [2, \"always\"]\n"
  },
  {
    "path": ".gitignore",
    "content": "node_modules\ntest/fixtures/*.actual.css\n"
  },
  {
    "path": ".travis.yml",
    "content": "sudo: false\nlanguage: node_js\nnode_js:\n  - \"6\"\n  - \"4\"\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# 4.1.0 - 2019-04-01\n\n- Added: `preserveCustomProps` option to preserve custom properties\n- Updated: `postcss` to 6.0.23 (patch)\n- Updated: `postcss-value-parser` to 3.3.1 (patch)\n\n# 4.0.1 - 2017-11-03\n\n- Fixed: bug when using the `tint`, `shade`, and `contrast` adjusters along with the `alpha` adjuster\n([#33](https://github.com/postcss/postcss-color-function/pull/33) - @tylergaw)\n\n# 4.0.0 - 2017-05-15\n\n- Added: compatibility with postcss v6.x\n- Updated dependencies\n\n# 3.0.0 - 2017-02-01\n\n- Changed: send postcss warning when color function cannot be parsed instead of throwing\n([#35](https://github.com/postcss/postcss-color-function/pull/35) - @drewbourne)\n- Changed: send a postcss message when color function contains a var()\n([#36](https://github.com/postcss/postcss-color-function/pull/36) - @drewbourne)\n\n# 2.0.1 - 2016-03-15\n\n- Fixed: whitespace are retained between color() usage.\n  ([#27](https://github.com/postcss/postcss-color-function/pull/27))\n\n# 2.0.0 - 2015-09-07\n\n- Removed: compatibility with postcss v4.x\n([#14](https://github.com/postcss/postcss-color-function/pull/14))\n- Added: compatibility with postcss v5.x\n([#14](https://github.com/postcss/postcss-color-function/pull/14))\n\n# 1.3.2 - 2015-07-08\n\n- Fixed: the plugin now do now transform all functions that match `*color(` but\nonly the one that are real color function call\n([#12](https://github.com/postcss/postcss-color-function/pull/12))\n\n# 1.3.1 - 2015-07-08 **YANKED**\n\n_This was just 1.3.0._\n\n# 1.3.0 - 2015-06-13\n\n- Changed: upgrade to PostCSS 4.1.x\n\n# 1.2.0 - 2015-03-12\n\n- Added: contrast() adjuster\n\n# 1.1.0 - 2014-11-25\n\n- Added: Enhanced exceptions\n\n# 1.0.0 - 2014-10-04\n\n✨ Initial release from [postcss-color](https://github.com/postcss/postcss-color)\n"
  },
  {
    "path": "LICENSE",
    "content": "The MIT License (MIT)\n\nCopyright (c) 2017 Maxime Thirouin & Ian Storm Taylor\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\nthe Software, and to permit persons to whom the Software is furnished to do so,\nsubject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\nFOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\nIN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\nCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# postcss-color-function [![Build Status](https://travis-ci.org/postcss/postcss-color-function.svg)](https://travis-ci.org/postcss/postcss-color-function)\n\n[PostCSS](https://github.com/postcss/postcss) plugin to transform CSS color function from editor draft of 'Color Module Level 4' specification to more compatible CSS.\n\n## Deprecated\n\n**⚠️ `color()` was changed to `color-mod()`. See [postcss-color-mod-function](https://github.com/jonathantneal/postcss-color-mod-function).**\n\n> There is a\n  [`color-mod`](https://github.com/jonathantneal/postcss-color-mod-function)\n  implementation.\n\n**⚠️ `color-mod()` has been removed from [Color Module Level 4 specification](https://www.w3.org/TR/css-color-4/#changes-from-20160705).**\n\n## Installation\n\n```console\nnpm install postcss-color-function\n```\n\n## Usage\n\n```js\n// dependencies\nvar fs = require(\"fs\")\nvar postcss = require(\"postcss\")\nvar colorFunction = require(\"postcss-color-function\")\n\n// css to be processed\nvar css = fs.readFileSync(\"input.css\", \"utf8\")\n\n// process css\n// set preserveCustomProps to `false` by default `true`\n//for delete declarations with custom properties\nvar output = postcss()\n  .use(colorFunction({preserveCustomProps: true}))\n  .process(css)\n  .css\n```\n\nUsing this `input.css`:\n\n```css\nbody {\n  background: color(red a(90%))\n}\n\n```\n\nyou will get:\n\n```css\nbody {\n  background: rgba(255, 0, 0, 0.9)\n}\n```\n\nCheckout [tests](test) for examples.\n\n## Interface (according to CSS specs)\n\n```\ncolor( [ <color> | <hue> ] <color-adjuster>* )\n```\n\n### List of `color-adjuster`\n\n- `[red( | green( | blue( | alpha( | a(] ['+' | '-']? [<number> | <percentage>] )`\n- `[red( | green( | blue( | alpha( | a(] '*' <percentage> )`\n- ~~`rgb( ['+' | '-'] [<number> | <percentage>]{3} )`~~ @todo\n- ~~`rgb( ['+' | '-'] <hash-token> )`~~ @todo\n- ~~`rgb( '*' <percentage> ) |`~~ @todo\n- `[hue( | h(] ['+' | '-' | '*']? <angle> )`\n- `[saturation( | s(] ['+' | '-' | '*']? <percentage> )`\n- `[lightness( | l(] ['+' | '-' | '*']? <percentage> )`\n- `[whiteness( | w(] ['+' | '-' | '*']? <percentage> )`\n- `[blackness( | b(] ['+' | '-' | '*']? <percentage> )`\n- `tint( <percentage> )`\n- `shade( <percentage> )`\n- `blend( <color> <percentage> [rgb | hsl | hwb]? )`\n- ~~`blenda( <color> <percentage> [rgb | hsl | hwb]? )`~~ @todo\n- `contrast( <percentage>? )`\n\nNotes:\n\n- some adjusts have shortcuts,\n- can be used on every value on any property,\n- some values can use add/subtract/scale modifiers or a direct value.\n\n### Examples\n\n```css\nwhatever {\n  color: color(red a(10%));\n\n  background-color: color(red lightness(50%)); /* == color(red l(50%)); */\n\n  border-color: color(hsla(125, 50%, 50%, .4) saturation(+ 10%) w(- 20%));\n}\n```\n\n## FAQ\n\n### Can you support `currentcolor` so we can do `color(currentcolor adjuster())`?\n\nNo we cannot do that. `currentcolor` depends on the cascade (so the DOM) and we can't handle that in a simple preprocessing step. You need to handle that with polyfills.\n\n### Can we use CSS custom properties so we can do `color(var(--mainColor) adjuster())`?\n\nBy using [postcss-custom-properties](https://github.com/postcss/postcss-custom-properties) before this plugin, you can do that (sort of).\nYou have some examples in [cssnext playground](http://cssnext.io/playground/).\n\n## Notes for former Sass users\n\n`lighten` and `darken` are Sass specific methods and not supported by native CSS specs. The same functionality can be achieved with the [tint and shade adjusters](https://drafts.csswg.org/css-color/#tint-shade-adjusters):\n\n```css\n$lighten(red, 20%)\n/*  is equivalent to */\ncolor(red tint(20%))\n\n$darken(red, 20%)\n/*  is equivalent to */\ncolor(red shade(20%))\n```\n\n---\n\n## [Changelog](CHANGELOG.md)\n\n## [License](LICENSE)\n"
  },
  {
    "path": "index.js",
    "content": "/**\n * Module dependencies.\n */\nvar postcss = require(\"postcss\")\nvar parser = require(\"postcss-value-parser\")\nvar colorFn = require(\"css-color-function\")\nvar helpers = require(\"postcss-message-helpers\")\n\nvar defaultOptions = {\n  preserveCustomProps: true,\n}\n\n/**\n * PostCSS plugin to transform color()\n */\nmodule.exports = postcss.plugin(\"postcss-color-function\", function(options) {\n  options = Object.assign({}, defaultOptions, options)\n\n  return function(style, result) {\n    style.walkDecls(function transformDecl(decl) {\n      if (!decl.value || decl.value.indexOf(\"color(\") === -1) {\n        return\n      }\n\n      if (decl.value.indexOf(\"var(\") !== -1) {\n        if (!options.preserveCustomProps) {\n          decl.remove()\n          return\n        }\n        result.messages.push({\n          plugin: \"postcss-color-function\",\n          type: \"skipped-color-function-with-custom-property\",\n          word: decl.value,\n          message:\n            \"Skipped color function with custom property `\" +\n            decl.value +\n            \"`\",\n        })\n        return\n      } \n\n      try {\n        decl.value = helpers.try(function transformColorValue() {\n          return transformColor(decl.value)\n        }, decl.source)\n      }\n      catch (error) {\n        decl.warn(result, error.message, {\n          word: decl.value,\n          index: decl.index,\n        })\n      }\n    })\n  }\n})\n\n/**\n * Transform color() to rgb()\n *\n * @param  {String} string declaration value\n * @return {String}        converted declaration value to rgba()\n */\nfunction transformColor(string) {\n  return parser(string).walk(function(node) {\n    if (node.type !== \"function\" || node.value !== \"color\") {\n      return\n    }\n\n    node.value = colorFn.convert(parser.stringify(node))\n    node.type = \"word\"\n  }).toString()\n}\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"postcss-color-function\",\n  \"version\": \"4.1.0\",\n  \"description\": \"PostCSS plugin to transform W3C CSS color function to more compatible CSS.\",\n  \"keywords\": [\n    \"css\",\n    \"postcss\",\n    \"postcss-plugin\",\n    \"color\",\n    \"colour\",\n    \"function\"\n  ],\n  \"author\": \"Maxime Thirouin\",\n  \"license\": \"MIT\",\n  \"repository\": \"https://github.com/postcss/postcss-color-function.git\",\n  \"files\": [\n    \"index.js\"\n  ],\n  \"dependencies\": {\n    \"css-color-function\": \"~1.3.3\",\n    \"postcss\": \"^6.0.23\",\n    \"postcss-message-helpers\": \"^2.0.0\",\n    \"postcss-value-parser\": \"^3.3.1\"\n  },\n  \"devDependencies\": {\n    \"eslint\": \"^3.19.0\",\n    \"faucet\": \"0.0.1\",\n    \"npmpub\": \"^3.1.0\",\n    \"tape\": \"^4.10.1\"\n  },\n  \"scripts\": {\n    \"lint\": \"eslint *.js index.js ./test/\",\n    \"test\": \"npm run lint && tape test | faucet\",\n    \"release\": \"npmpub\"\n  }\n}\n"
  },
  {
    "path": "test/fixtures/color-with-custom-properties.css",
    "content": "body {\n  color: color(var(--red));\n  color: color(var(--red) tint(50%));\n  color: color(var(--red) tint(var(--tintPercent)));\n  color: color(rgb(255, 0, 0) tint(var(--tintPercent)));\n}\n"
  },
  {
    "path": "test/fixtures/color-with-custom-properties.expected.css",
    "content": "body {\n  color: color(var(--red));\n  color: color(var(--red) tint(50%));\n  color: color(var(--red) tint(var(--tintPercent)));\n  color: color(rgb(255, 0, 0) tint(var(--tintPercent)));\n}\n"
  },
  {
    "path": "test/fixtures/color.css",
    "content": "body {\n  color: color(red);\n  background-color: color(red tint(50%));\n  border-color: color(hsla(125, 50%, 50%, .4) hue(200));\n  border-top-color: color(hwb(270, 10%, 0%) contrast(50%));\n\n  border-bottom-color: hover-color(red);\n\n  border-right-color: hover-color(color(red tint(50%)));\n\n  border-color: color(#999 a(0.8)) color(#999 a(0.8));\n}\n\n.withAlpha {\n  color: color(black a(80%) contrast(99%));\n  background-color: color(red a(50%) shade(50%));\n  border-color: color(red a(80%) tint(50%));\n}\n"
  },
  {
    "path": "test/fixtures/color.expected.css",
    "content": "body {\n  color: rgb(255, 0, 0);\n  background-color: rgb(255, 128, 128);\n  border-color: rgba(64, 149, 191, 0.4);\n  border-top-color: rgb(248, 240, 255);\n\n  border-bottom-color: hover-color(red);\n\n  border-right-color: hover-color(rgb(255, 128, 128));\n\n  border-color: rgba(153, 153, 153, 0.8) rgba(153, 153, 153, 0.8);\n}\n\n.withAlpha {\n  color: rgba(255, 255, 255, 0.8);\n  background-color: rgba(128, 0, 0, 0.5);\n  border-color: rgba(255, 128, 128, 0.8);\n}\n"
  },
  {
    "path": "test/fixtures/delete-custom-properties.css",
    "content": "body {\n  color: color(var(--red));\n  color: color(var(--red) tint(50%));\n  background-color: color(red tint(50%));\n  color: color(var(--red) tint(var(--tintPercent)));\n  color: color(rgb(255, 0, 0) tint(var(--tintPercent)));\n}\n"
  },
  {
    "path": "test/fixtures/delete-custom-properties.expected.css",
    "content": "body {\n  background-color: rgb(255, 128, 128);\n}\n"
  },
  {
    "path": "test/fixtures/error.css",
    "content": "body {\n  background: color(blurp a(+10%));\n}\n"
  },
  {
    "path": "test/index.js",
    "content": "var fs = require(\"fs\")\n\nvar test = require(\"tape\")\n\nvar postcss = require(\"postcss\")\nvar plugin = require(\"..\")\n\nfunction filename(name) {\n  return \"test/\" + name + \".css\"\n}\n\nfunction read(name) {\n  return fs.readFileSync(name, \"utf8\")\n}\n\nfunction compareFixtures(t, name, msg, opts, postcssOpts) {\n  postcssOpts = postcssOpts || {}\n  postcssOpts.from = filename(\"fixtures/\" + name)\n  opts = opts || {}\n  var actual = postcss().use(plugin(opts))\n    .process(read(postcssOpts.from), postcssOpts).css\n  var expected = read(filename(\"fixtures/\" + name + \".expected\"))\n  fs.writeFileSync(filename(\"fixtures/\" + name + \".actual\"), actual)\n  t.equal(actual, expected, msg)\n}\n\ntest(\"color()\", function(t) {\n  compareFixtures(t, \"color\", \"should transform color()\")\n  t.end()\n})\n\ntest(\"logs warning when color() value cannot be parsed\", function(t) {\n  postcss(plugin()).process(read(filename(\"fixtures/error\")))\n    .then(function(result) {\n      var warnings = result.warnings()\n      t.equals(warnings.length, 1, \"expected only 1 warning\")\n\n      var warning = warnings[0]\n      t.equals(\n        warning.plugin,\n        \"postcss-color-function\",\n        \"expected `warning.plugin` to match this plugin's name\"\n      )\n\n      t.equals(\n        warning.word,\n        \"color(blurp a(+10%))\",\n        \"expected `warning.word` to match color() declaration\"\n      )\n\n      t.equals(\n        warning.text,\n        \"<css input>:2:3: Unable to parse color from string \\\"blurp\\\"\",\n        \"expected `warning.text` to contain a readable error \" +\n        \"when a color can't be parsed\"\n      )\n\n      t.end()\n    })\n})\n\ntest(\"logs message when color() contains var() custom property\", function(t) {\n  postcss(plugin()).process(\n    read(filename(\"fixtures/color-with-custom-properties\"))\n  ).then(function(result) {\n    var expectedWords = [\n      \"color(var(--red))\",\n      \"color(var(--red) tint(50%))\",\n      \"color(var(--red) tint(var(--tintPercent)))\",\n      \"color(rgb(255, 0, 0) tint(var(--tintPercent)))\",\n    ]\n\n    t.equal(\n      result.messages.length,\n      expectedWords.length,\n      \"expected a message every time a color function is skipped\"\n    )\n\n    result.messages.forEach(function(message, i) {\n      t.equal(\n        message.type,\n        \"skipped-color-function-with-custom-property\",\n        \"expected `message.type` to indicate reason for message\"\n      )\n\n      t.equal(\n        message.plugin,\n        \"postcss-color-function\",\n        \"expected `message.plugin` to match this plugin's name\"\n      )\n\n      t.equal(\n        message.word,\n        expectedWords[i],\n        \"expected `message.word` to contain declaration value\"\n      )\n\n      t.equal(\n        message.message,\n        \"Skipped color function with custom property \" +\n        \"`\" + expectedWords[i] + \"`\",\n        \"expected `message.message` to contain reason for message\"\n      )\n    })\n\n    t.end()\n  })\n})\n\ntest(\n  \"test delete custom properties with option preserveCustomProps `false`\", \n  function(t) {\n    postcss(plugin({preserveCustomProps : false})).process(\n      read(filename(\"fixtures/delete-custom-properties\"))\n    ).then(function(result) {\n      var expectedDeclaration = [{\n        prop: \"background-color\",\n        value: \"rgb(255, 128, 128)\",\n      }]\n      // check left rules in body after clear\n      var declNodes = result.root.nodes[0].nodes\n      t.equal(\n        declNodes.length,\n        expectedDeclaration.length,\n        \"expected \" + expectedDeclaration.length +\n        \" declaration length but got \" + declNodes.length\n      )\n\n      t.equal(\n        declNodes[0].prop,\n        expectedDeclaration[0].prop,\n        \"expected declaration with \"+ expectedDeclaration[0].prop +\n        \" property but got \" + declNodes[0].prop\n      )\n\n      t.equal(\n        declNodes[0].value,\n        expectedDeclaration[0].value,\n        \"expected declaration with \"+ expectedDeclaration[0].value +\n        \" value but got \" + declNodes[0].value\n      )\n\n      t.end()\n    })\n  }\n)\n"
  }
]