Giter Site home page Giter Site logo

demiazz / postcss-color-function Goto Github PK

View Code? Open in Web Editor NEW

This project forked from postcss/postcss-color-function

0.0 3.0 0.0 97 KB

PostCSS plugin to transform W3C CSS color function to more compatible CSS

License: MIT License

JavaScript 100.00%

postcss-color-function's Introduction

postcss-color-function Build Status

PostCSS plugin to transform W3C CSS color function to more compatible CSS.

http://dev.w3.org/csswg/css-color/#modifying-colors

Installation

$ npm install postcss-color-function

Usage

// 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:

body {
  background: color(red a(90%))
}

you will get:

body {
  background: rgba(255, 0, 0, 0.9)
}

Checkout tests for examples.

Interface (according to CSS specs)

color( [ <color> | <hue> ] <color-adjuster>* )

List of color-adjuster

  • [red( | green( | blue( | alpha( | a(] ['+' | '-']? [<number> | <percentage>] )
  • [red( | green( | blue( | alpha( | a(] '*' <percentage> )
  • rgb( ['+' | '-'] [<number> | <percentage>]{3} ) @todo
  • rgb( ['+' | '-'] <hash-token> ) @todo
  • rgb( '*' <percentage> ) | @todo
  • [hue( | h(] ['+' | '-' | '*']? <angle> )
  • [saturation( | s(] ['+' | '-' | '*']? <percentage> )
  • [lightness( | l(] ['+' | '-' | '*']? <percentage> )
  • [whiteness( | w(] ['+' | '-' | '*']? <percentage> )
  • [blackness( | b(] ['+' | '-' | '*']? <percentage> )
  • tint( <percentage> )
  • shade( <percentage> )
  • blend( <color> <percentage> [rgb | hsl | hwb]? )
  • blenda( <color> <percentage> [rgb | hsl | hwb]? ) @todo
  • contrast( <percentage>? )

Notes:

  • some adjusts have shortcuts,
  • can be used on every value on any property,
  • some values can use add/subtract/scale modifiers or a direct value.

Read the specs for more information.

Examples

whatever {
  color: color(red a(10%));
  
  background-color: color(red lightness(50%)); /* == color(red l(50%)); */
  
  border-color: color(hsla(125, 50%, 50%, .4) saturation(+ 10%) w(- 20%));
}

FAQ

Can you support currentcolor so we can do color(currentcolor adjuster())?

No 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.

Can we use CSS custom properties so we can do color(var(--mainColor) adjuster())?

By using postcss-custom-properties before this plugin, you can do that (sort of). You have some examples in cssnext playground.


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

postcss-color-function's People

Contributors

moox avatar trysound avatar vanwagonet avatar dy avatar

Watchers

Alexey Plutalov avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.