Permalink
Browse files

Initial release from postcss-color

  • Loading branch information...
0 parents commit b5b24748a86cc7ee79f3f6afd318f89940081871 @MoOx MoOx committed Oct 4, 2014
Showing with 399 additions and 0 deletions.
  1. +16 −0 .editorconfig
  2. +2 −0 .gitignore
  3. +130 −0 .jscsrc
  4. +9 −0 .jshintrc
  5. +1 −0 .travis.yml
  6. +3 −0 CHANGELOG.md
  7. +20 −0 LICENSE
  8. +61 −0 README.md
  9. +73 −0 index.js
  10. +39 −0 package.json
  11. +5 −0 test/fixtures/color.css
  12. +5 −0 test/fixtures/color.expected.css
  13. +3 −0 test/fixtures/error.css
  14. +32 −0 test/index.js
@@ -0,0 +1,16 @@
+# editorconfig.org
+root = true
+
+[*]
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+indent_style = space
+indent_size = 2
+
+[*.md]
+trim_trailing_whitespace = false
+
+[Makefile]
+indent_style = tab
@@ -0,0 +1,2 @@
+node_modules
+test/fixtures/*.actual.css
@@ -0,0 +1,130 @@
+{
+ "excludeFiles": [
+ "node_modules/**"
+ ],
+ "fileExtensions": [
+ ".js"
+ ],
+ "requireCurlyBraces": [
+ "if",
+ "else",
+ "for",
+ "while",
+ "do",
+ "try",
+ "catch"
+ ],
+ "requireSpaceAfterKeywords": [
+ "if",
+ "else",
+ "for",
+ "while",
+ "do",
+ "switch",
+ "return",
+ "try",
+ "catch"
+ ],
+ "requireSpaceBeforeBlockStatements": true,
+ "requireParenthesesAroundIIFE": true,
+ "requireSpacesInConditionalExpression": {
+ "afterTest": true,
+ "beforeConsequent": true,
+ "afterConsequent": true,
+ "beforeAlternate": true
+ },
+ "requireSpacesInFunctionExpression": {
+ "beforeOpeningCurlyBrace": true
+ },
+ "disallowSpacesInFunctionExpression": {
+ "beforeOpeningRoundBrace": true
+ },
+ "disallowMultipleVarDecl": true,
+ "requireBlocksOnNewline": 1,
+ "disallowPaddingNewlinesInBlocks": true,
+ "disallowEmptyBlocks": true,
+ "disallowSpacesInsideObjectBrackets": true,
+ "disallowSpacesInsideArrayBrackets": true,
+ "disallowSpacesInsideParentheses": true,
+ "disallowQuotedKeysInObjects": "allButReserved",
+ "disallowSpaceAfterObjectKeys": true,
+ "requireCommaBeforeLineBreak": true,
+ "requireOperatorBeforeLineBreak": [
+ "?",
+ "+",
+ "-",
+ "/",
+ "*",
+ "=",
+ "==",
+ "===",
+ "!=",
+ "!==",
+ ">",
+ ">=",
+ "<",
+ "<="
+ ],
+ "disallowSpaceAfterPrefixUnaryOperators": [
+ "++",
+ "--",
+ "+",
+ "-",
+ "~",
+ "!"
+ ],
+ "disallowSpaceBeforePostfixUnaryOperators": [
+ "++",
+ "--"
+ ],
+ "requireSpaceBeforeBinaryOperators": [
+ "+",
+ "-",
+ "/",
+ "*",
+ "=",
+ "==",
+ "===",
+ "!=",
+ "!=="
+ ],
+ "requireSpaceAfterBinaryOperators": [
+ "+",
+ "-",
+ "/",
+ "*",
+ "=",
+ "==",
+ "===",
+ "!=",
+ "!=="
+ ],
+ "disallowImplicitTypeConversion": [
+ "numeric",
+ "boolean",
+ "binary",
+ "string"
+ ],
+ "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
+ "disallowKeywords": [
+ "with"
+ ],
+ "disallowMultipleLineStrings": true,
+ "validateQuoteMarks": "\"",
+ "validateIndentation": 2,
+ "disallowMixedSpacesAndTabs": true,
+ "disallowTrailingWhitespace": true,
+ "requireKeywordsOnNewLine": [
+ "else"
+ ],
+ "requireLineFeedAtFileEnd": true,
+ "requireCapitalizedConstructors": true,
+ "safeContextKeyword": "that",
+ "requireDotNotation": true,
+ "validateJSDoc": {
+ "checkParamNames": true,
+ "checkRedundantParams": true,
+ "requireParamTypes": true
+ },
+ "requireSpaceAfterLineComment": true
+}
@@ -0,0 +1,9 @@
+{
+ "newcap": false,
+ "undef": true,
+ "unused": true,
+ "asi": true,
+ "esnext": true,
+ "node": true,
+ "browser": true
+}
@@ -0,0 +1 @@
+language: node_js
@@ -0,0 +1,3 @@
+# 1.0.0 - 2014-10-04
+
+Initial release from [postcss-color](https://github.com/postcss/postcss-color)
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2014 Maxime Thirouin & Ian Storm Taylor
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
+# postcss-color-function [![Build Status](https://travis-ci.org/postcss/postcss-color-function.png)](https://travis-ci.org/postcss/postcss-color-function)
+
+> [PostCSS](https://github.com/postcss/postcss) plugin to transform [W3C CSS color function](http://dev.w3.org/csswg/css-color/#modifying-colors) to more compatible CSS.
+
+## Installation
+
+```bash
+$ npm install postcss-color-function
+```
+
+## Usage
+
+```js
+// dependencies
+var fs = require("fs")
+var postcss = require("postcss")
+var colorFunction = require("postcss-color-function")
+
+// css to be processed
+var css = fs.readFileSync("input.css", "utf8")
+
+// process css
+var output = postcss()
+ .use(colorFunction())
+ .process(css)
+ .css
+```
+
+Using this `input.css`:
+
+```css
+body {
+ background: color(red a(90%))
+}
+
+```
+
+you will get:
+
+```css
+body {
+ background: rgba(255, 0, 0, 0.9)
+}
+```
+
+Checkout [tests](test) for more examples.
+
+---
+
+## Contributing
+
+Work on a branch, install dev-dependencies, respect coding style & run tests before submitting a bug fix or a feature.
+
+ $ git clone https://github.com/postcss/postcss-color-function.git
+ $ git checkout -b patch-1
+ $ npm install
+ $ npm test
+
+## [Changelog](CHANGELOG.md)
+
+## [License](LICENSE)
@@ -0,0 +1,73 @@
+/**
+ * Module dependencies.
+ */
+var balanced = require("balanced-match")
+var colorFn = require("css-color-function")
+
+/**
+ * PostCSS plugin to transform color()
+ */
+module.exports = function plugin() {
+ return function(style) {
+ style.eachDecl(function transformDecl(dec) {
+ if (!dec.value) {
+ return
+ }
+
+ dec.value = transform(dec.value, dec.source)
+ })
+ }
+}
+
+/**
+ * Transform colors to rgb() or rgba() on a declaration value
+ *
+ * @param {String} string
+ * @return {String}
+ */
+function transform(string, source) {
+ // order of transformation is important
+
+ try {
+ if (string.indexOf("color(") > -1) {
+ string = transformColor(string, source)
+ }
+ }
+ catch (e) {
+ throw new Error(gnuMessage(e.message, source))
+ }
+
+ return string
+}
+
+/**
+ * Transform color() to rgb()
+ *
+ * @param {String} string declaration value
+ * @return {String} converted declaration value to rgba()
+ */
+function transformColor(string, source) {
+ var index = string.indexOf("color(")
+ if (index == -1) {
+ return string
+ }
+
+ var fn = string.slice(index)
+ var balancedMatches = balanced("(", ")", fn)
+ if (!balancedMatches) {
+ throw new SyntaxError(gnuMessage("Missing closing parentheses in '" + string + "'", source))
+ }
+
+ return string.slice(0, index) + colorFn.convert("color(" + balancedMatches.body + ")") + transformColor(balancedMatches.post)
+}
+
+
+/**
+ * return GNU style message
+ *
+ * @param {String} message
+ * @param {Object} source
+ */
+function gnuMessage(message, source) {
+ return (source ? (source.file ? source.file : "<css input>") + ":" + source.start.line + ":" + source.start.column : "") + " " + message
+}
@@ -0,0 +1,39 @@
+{
+ "name": "postcss-color-function",
+ "version": "0.0.0",
+ "description": "PostCSS plugin to transform W3C CSS color function to more compatible CSS.",
+ "keywords": [
+ "css",
+ "postcss",
+ "postcss-plugins",
+ "color",
+ "colour",
+ "function"
+ ],
+ "author": "Maxime Thirouin",
+ "license": "MIT",
@necolas
necolas Oct 6, 2014 Member

here is your existing license info

@MoOx
MoOx Oct 6, 2014 Member

I'm not sure if this is enough according to the text of the license. Maybe you are right.
That being said I'm not a lawyer & don't understand all the things about licensing :)
I just want to ship stuff but one day I read this http://blog.codinghorror.com/pick-a-license-any-license/

+ "repository": {
+ "type": "git",
+ "url": "https://github.com/postcss/postcss-color-function.git"
+ },
+ "files": [
+ "CHANGELOG.md",
+ "LICENSE",
@necolas
necolas Oct 4, 2014 Member

fyi, npm will always install the readme and license even without these lines.

@MoOx
MoOx Oct 5, 2014 Member

Oh. I feel so dumb.
I'll update a bunch of repos then :)
Thanks !

@MoOx
MoOx Oct 5, 2014 Member

I just take a quick look to some repo vs package (eg https://github.com/suitcss/components-grid) & package just have the README. LICENSE is not added automatically.
Also this is weird cause I saw "readme": "ERROR: No README data found!" in this package.json
I've checked the doc, no sign of this behavior for the license.

@necolas
necolas Oct 5, 2014 Member

true, license is not added. but in this case you've already got it referenced in the package.json

@MoOx
MoOx Oct 6, 2014 Member

Not from what I saw here :/

@necolas
necolas Oct 6, 2014 Member

that's not the package.json for this module though!

@MoOx
MoOx Oct 6, 2014 Member

Yeah I was just wondering if I should just omit "README.md".

+ "README.md",
+ "index.js"
+ ],
+ "dependencies": {
+ "balanced-match": "^0.1.0",
+ "css-color-function": "^1.1.1"
+ },
+ "devDependencies": {
+ "jscs": "^1.6.2",
+ "jshint": "^2.5.6",
+ "postcss": "^2.2.5",
+ "tape": "^3.0.0"
+ },
+ "scripts": {
+ "lint": "jscs *.js **/*.js && jshint . --exclude-path .gitignore",
+ "test": "npm run lint && tape test"
+ }
+}
@@ -0,0 +1,5 @@
+body {
+ color: color(red);
+ background-color: color(red tint(50%));
+ border-color: color(hsla(125, 50%, 50%, .4) hue(200));
+}
@@ -0,0 +1,5 @@
+body {
+ color: rgb(255, 0, 0);
+ background-color: rgb(255, 128, 128);
+ border-color: rgba(64, 149, 191, 0.4);
+}
@@ -0,0 +1,3 @@
+body {
+ background: color(blurp a(+10%));
+}
Oops, something went wrong.

0 comments on commit b5b2474

Please sign in to comment.