Giter Club home page Giter Club logo

postcss-color-function's Introduction

PostCSS

Philosopher’s stone, logo of PostCSS

PostCSS is a tool for transforming styles with JS plugins. These plugins can lint your CSS, support variables and mixins, transpile future CSS syntax, inline images, and more.

PostCSS is used by industry leaders including Wikipedia, Twitter, Alibaba, and JetBrains. The Autoprefixer and Stylelint PostCSS plugins is one of the most popular CSS tools.


  Made in Evil Martians, product consulting for developer tools.


Sponsorship

PostCSS needs your support. We are accepting donations at Open Collective.

Sponsored by Tailwind CSS        Sponsored by ThemeIsle

Plugins

PostCSS takes a CSS file and provides an API to analyze and modify its rules (by transforming them into an Abstract Syntax Tree). This API can then be used by plugins to do a lot of useful things, e.g., to find errors automatically, or to insert vendor prefixes.

Currently, PostCSS has more than 200 plugins. You can find all of the plugins in the plugins list or in the searchable catalog. Below is a list of our favorite plugins — the best demonstrations of what can be built on top of PostCSS.

If you have any new ideas, PostCSS plugin development is really easy.

Solve Global CSS Problem

  • postcss-use allows you to explicitly set PostCSS plugins within CSS and execute them only for the current file.
  • postcss-modules and react-css-modules automatically isolate selectors within components.
  • postcss-autoreset is an alternative to using a global reset that is better for isolatable components.
  • postcss-initial adds all: initial support, which resets all inherited styles.
  • cq-prolyfill adds container query support, allowing styles that respond to the width of the parent.

Use Future CSS, Today

Better CSS Readability

Images and Fonts

Linters

  • stylelint is a modular stylesheet linter.
  • stylefmt is a tool that automatically formats CSS according stylelint rules.
  • doiuse lints CSS for browser support, using data from Can I Use.
  • colorguard helps you maintain a consistent color palette.

Other

  • cssnano is a modular CSS minifier.
  • lost is a feature-rich calc() grid system.
  • rtlcss mirrors styles for right-to-left locales.

Syntaxes

PostCSS can transform styles in any syntax, not just CSS. If there is not yet support for your favorite syntax, you can write a parser and/or stringifier to extend PostCSS.

  • sugarss is a indent-based syntax like Sass or Stylus.
  • postcss-syntax switch syntax automatically by file extensions.
  • postcss-html parsing styles in <style> tags of HTML-like files.
  • postcss-markdown parsing styles in code blocks of Markdown files.
  • postcss-styled-syntax parses styles in template literals CSS-in-JS like styled-components.
  • postcss-jsx parsing CSS in template / object literals of source files.
  • postcss-styled parsing CSS in template literals of source files.
  • postcss-scss allows you to work with SCSS (but does not compile SCSS to CSS).
  • postcss-sass allows you to work with Sass (but does not compile Sass to CSS).
  • postcss-less allows you to work with Less (but does not compile LESS to CSS).
  • postcss-less-engine allows you to work with Less (and DOES compile LESS to CSS using true Less.js evaluation).
  • postcss-js allows you to write styles in JS or transform React Inline Styles, Radium or JSS.
  • postcss-safe-parser finds and fixes CSS syntax errors.
  • midas converts a CSS string to highlighted HTML.

Articles

More articles and videos you can find on awesome-postcss list.

Books

Usage

You can start using PostCSS in just two steps:

  1. Find and add PostCSS extensions for your build tool.
  2. Select plugins and add them to your PostCSS process.

CSS-in-JS

The best way to use PostCSS with CSS-in-JS is astroturf. Add its loader to your webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'postcss-loader'],
      },
      {
        test: /\.jsx?$/,
        use: ['babel-loader', 'astroturf/loader'],
      }
    ]
  }
}

Then create postcss.config.js:

/** @type {import('postcss-load-config').Config} */
const config = {
  plugins: [
    require('autoprefixer'),
    require('postcss-nested')
  ]
}

module.exports = config

Parcel

Parcel has built-in PostCSS support. It already uses Autoprefixer and cssnano. If you want to change plugins, create postcss.config.js in project’s root:

/** @type {import('postcss-load-config').Config} */
const config = {
  plugins: [
    require('autoprefixer'),
    require('postcss-nested')
  ]
}

module.exports = config

Parcel will even automatically install these plugins for you.

Please, be aware of the several issues in Version 1. Notice, Version 2 may resolve the issues via issue #2157.

Webpack

Use postcss-loader in webpack.config.js:

module.exports = {
  module: {
    rules: [
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: [
          {
            loader: 'style-loader',
          },
          {
            loader: 'css-loader',
            options: {
              importLoaders: 1,
            }
          },
          {
            loader: 'postcss-loader'
          }
        ]
      }
    ]
  }
}

Then create postcss.config.js:

/** @type {import('postcss-load-config').Config} */
const config = {
  plugins: [
    require('autoprefixer'),
    require('postcss-nested')
  ]
}

module.exports = config

Gulp

Use gulp-postcss and gulp-sourcemaps.

gulp.task('css', () => {
  const postcss    = require('gulp-postcss')
  const sourcemaps = require('gulp-sourcemaps')

  return gulp.src('src/**/*.css')
    .pipe( sourcemaps.init() )
    .pipe( postcss([ require('autoprefixer'), require('postcss-nested') ]) )
    .pipe( sourcemaps.write('.') )
    .pipe( gulp.dest('build/') )
})

npm Scripts

To use PostCSS from your command-line interface or with npm scripts there is postcss-cli.

postcss --use autoprefixer -o main.css css/*.css

Browser

If you want to compile CSS string in browser (for instance, in live edit tools like CodePen), just use Browserify or webpack. They will pack PostCSS and plugins files into a single file.

To apply PostCSS plugins to React Inline Styles, JSS, Radium and other CSS-in-JS, you can use postcss-js and transforms style objects.

const postcss  = require('postcss-js')
const prefixer = postcss.sync([ require('autoprefixer') ])

prefixer({ display: 'flex' }) //=> { display: ['-webkit-box', '-webkit-flex', '-ms-flexbox', 'flex'] }

Runners

JS API

For other environments, you can use the JS API:

const autoprefixer = require('autoprefixer')
const postcss = require('postcss')
const postcssNested = require('postcss-nested')
const fs = require('fs')

fs.readFile('src/app.css', (err, css) => {
  postcss([autoprefixer, postcssNested])
    .process(css, { from: 'src/app.css', to: 'dest/app.css' })
    .then(result => {
      fs.writeFile('dest/app.css', result.css, () => true)
      if ( result.map ) {
        fs.writeFile('dest/app.css.map', result.map.toString(), () => true)
      }
    })
})

Read the PostCSS API documentation for more details about the JS API.

All PostCSS runners should pass PostCSS Runner Guidelines.

Options

Most PostCSS runners accept two parameters:

  • An array of plugins.
  • An object of options.

Common options:

  • syntax: an object providing a syntax parser and a stringifier.
  • parser: a special syntax parser (for example, SCSS).
  • stringifier: a special syntax output generator (for example, Midas).
  • map: source map options.
  • from: the input file name (most runners set it automatically).
  • to: the output file name (most runners set it automatically).

Treat Warnings as Errors

In some situations it might be helpful to fail the build on any warning from PostCSS or one of its plugins. This guarantees that no warnings go unnoticed, and helps to avoid bugs. While there is no option to enable treating warnings as errors, it can easily be done by adding postcss-fail-on-warn plugin in the end of PostCSS plugins:

module.exports = {
  plugins: [
    require('autoprefixer'),
    require('postcss-fail-on-warn')
  ]
}

Editors & IDE Integration

VS Code

Sublime Text

Vim

WebStorm

To get support for PostCSS in WebStorm and other JetBrains IDEs you need to install this plugin.

Security Contact

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

For Enterprise

Available as part of the Tidelift Subscription.

The maintainers of postcss and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

postcss-color-function's People

Contributors

ai avatar ar53n avatar avanes avatar demiazz avatar drewbourne avatar dy avatar jonathantneal avatar moox avatar semigradsky avatar ser-gen avatar thoiberg avatar trysound avatar tylergaw avatar vanwagonet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

postcss-color-function's Issues

Please add support for fractional percentages

Hello, I’m trying to hit a specific rgb result value with my color transformations and finding there’s no support for fractional percentages.

Input

fire {
  color: color(rgba(29, 29, 31, 1) tint(4%));
}

water {
  color: color(rgba(29, 29, 31, 1) tint(4.3%));
}

Output

fire {
  color: rgb(38, 38, 40);
}

water {
  color: rgb(38, 38, 40);
}

Thanks for creating this wonderful polyfill. It’s been awesome to use.

Should this support linear gradients?

Would you expect these color functions to work with linear-gradients? For example, I'd expect this to tint the entire gradient, but it seems to not work that way.

--gradient: linear-gradient(90deg, #00C0FF 0%, #FFCF00 49%, #FC4F4F 100%);
--gradient-hover: color(var(--gradient) tint(20%));

blackness and lightness vs sass darken lighten

I am trying to replicate the results of the sass darken and lighten functions using the css color function, however, I am not getting similar results:

/* color-function */
color(#B6FFD4 blackness(30%)) /* #b3b3b3 */

/* sass darken */
darken(#B6FFD4, 30%) /* #1dff7a */

Basically I want a stronger green, which is what I get using sass darken, but I can't figure out how to replicate those results. Thanks!

Unable to parse color from string "$primary-color"

I am using postcss-advanced-variables and if i try to put variables into my color values I get the following error:

Unable to parse color from string "$primary-color"

this is my postcss line up:

    'postcss-import': {},
	'postcss-at-rules-variables' : {},
	'postcss-nested-ancestors' : {},
	level4 : {},
	'postcss-for' : {},
	'postcss-each' : {},
	'postcss-sassy-mixins' : {},
	'postcss-advanced-variables' : {},
	'postcss-conditionals' : {},
	'postcss-hexrgba' : {},
	'postcss-object-fit-images' : {},
	'postcss-flexbugs-fixes' : {},
	'postcss-quantity-queries' : {},
	'postcss-size' : {},
	'postcss-will-change' : {},
	'postcss-nested' : {},
	'postcss-easings' : {},
	'postcss-random' : {},
	'postcss-calc' : {
		warnWhenCannotResolve: false,
		mediaQueries: true,
	},
	'postcss-inline-svg' : {
		path: 'src/svg',
		encode: function encode(code) {
		    return code
		        .replace(/%/g, '%25')
		        .replace(/</g, '%3C')
		        .replace(/>/g, '%3E')
		        .replace(/&/g, '%26')
		        .replace(/#/g, '%23');
		},
		removeFill: true,
	},
	'postcss-initial' : {},
	autoprefixer : { browsers },
	'postcss-color-function' : {},
	cssnano : ctx.env === 'production' ? {
		filterPlugins: false,
		safe: true,
		mergeRules: false,
		browsers,
		discardComments: {
			removeAll: true,
		},
	} : false,

Wrong output when using the * operator and <percentage>

The color hsl(0, 0%, 10%) with lightness multiplied by 5% should be nearly black, but the output seems to be hsl(0, 0%, 10% * 5) == rgb(128, 128, 128) rather than hsl(0, 0%, 10% * 5%). If use 0.05 instead the output is correct.

test.css:

.test1 {
    background-color: color(hsl(0, 0%, 10%) lightness(* 5%));
}
.test2 {
    background-color: color(hsl(0, 0%, 10%) lightness(* 0.05));
}

postcss.config.js:

module.exports = {
    plugins: {
        'postcss-color-function': {},
    },
}

Output:

nia@nia-PC [~/temp/test] $ ./node_modules/.bin/postcss test.css
✔ Finished test.css (17 ms)
.test1 {
    background-color: rgb(128, 128, 128);
}
.test2 {
    background-color: rgb(3, 3, 3);
}
nia@nia-PC [~/temp/test] $

The version is 4.0.0

nia@nia-PC [~/temp/test] $ npm list postcss-color-function
/home/nia/temp/test
└── [email protected]

Since the spec says we should use <percentage>, I think this is a bug.

Hex color values

Is there any particular reason that hex values aren't supported currently? I'm trying to work from a base palette defined as variables but they were defined in hex as the designer specified them. Seems like this should work but I get:

Unable to parse color from string "#ffffff,"

I suppose it's just an issue with the spec, it's odd how they provide the results in their examples as hex. But only rgb/hsl/hwb for input?

blend() parsing error for rgb colors

Input:

background-color: color(rgb(1,1,1) blend(red 50%));

Output:

background-color: rgb(128, 1, 1);

Input:

background-color: color(rgb(1,1,1) blend(rgb(2,2,2) 50%));

Output:

Error: :2:3: Unable to parse color from string "rgb(2,2,2"

Blackness and Lightness API Symmetry

Hi,

I'm working with the lightness and blackness functions ATM. Blackness works the way I expect. For example if I do:

  --color-primary-700: color(var(--color-primary) blackness(15%));

The resulting color is slightly darker. The higher the percentage the darker the color. I specify 0%, the color is the same.

On the other hand the lightness functions seems to start at 50%, instead of 0%. So if I specify 50% I get approximately the same color. If I specify a value greater than 50%, I get a lighter color. Less than 50% yields a darker color.

It would be nice if both lightness and darkness were symmetrical with respect to how output corresponds to input. I'm put a test below:

:root {
  --color-primary:         #0275d8;
  --color-primary-100: color(var(--color-primary) lightness(30%));
  --color-primary-300: color(var(--color-primary) lightness(15%));
  --color-primary-500: var(--color-primary);
  --color-primary-700: color(var(--color-primary) blackness(15%));
  --color-primary-900: color(var(--color-primary) blackness(30%));
}

/* 4 */
@each $variation in 100, 300, 500, 700, 900 {
  @each $brand in primary {
    .u-color-background-$(brand)-$(variation) {background-color: var(--color-$(brand)-$(variation));
    }
  }
}

When I run this I'm expecting the section:

  --color-primary-100: color(var(--color-primary) lightness(30%));
  --color-primary-300: color(var(--color-primary) lightness(15%));

To yield colors that are slightly lighter, but instead I get colors that are darker than the primary color, with the lightness(15%) one being darker than the lightness(30%) one.

Thoughts?

Cheers,
Ole

Support Custom Properties

If a developer wants to use Custom Properties with this plugin, could this plugin lookup the variables for them? Even if it’s just on :root?

Currently, this plugin relies on PostCSS Custom Properties to remove var() usage, but 1. that’s not very future-leaning, and 2. the new major release of PostCSS Custom Properties preserves var() usage by default.

:root {
  --brand: #00bdbd;
  --dark-brand: color(var(--brand) shade(20%));
}

becomes

:root {
  --brand: #00bdbd;
  --dark-brand: color(var(--brand) shade(20%));
}

Unfortunately, it seems this plugin was never tested against Custom Properties with the preserve option enabled.

postcss/postcss-custom-properties#99
postcss/postcss-custom-properties#98

Custom properties not working as function parameter

We have our CSS custom props defined in a JSON file which is imported like:

'postcss-cssnext': {
      browsers: ['>.25%', 'IE 8'],
      features: {
        { '--color-primary': red },
      },
    },

We can then use that var as normal with no issues
Then trying to use it with the color() function:

&:active {
  border-color: color(var(--color-primary) shade(20%));
}

And this doesn't work. The resulting color is just black.

Doing:

&:active {
  border-color: color(red shade(20%));
}

does work

support for currentcolor

It would be nice to support color(currentcolor color-adjuster())

by the way, thx for this project !

use CSS Custom Property for alpha value

Hi, I was using this module to assign a custom alpha value to some HEX values:

--opacity: .5
$black: #000

color: color($black alpha(var(--opacity)))

I actually remember it worked just fine a week ago, and it transpiled it to:

color: rgba(0,0,0, var(--opacity))

But today I tried it again and now I see that it simply ignores the alpha modifier and outputs:

color: rgb(0,0,0)

Am I doing something wrong, does this plugin supports this? If not, why?
I understand that it can't work if I wanted to do color(var(--red), .5) because the plugin can't know the value of --red, but in this case it's simply a matter of keep the var instead of the alpha value.

Use PostCSS 4.1 API

PostCSS Plugin Guidelines are mandatory right now. Because all of rules are about ecosystem health.

Lighten support

Good evening guys,

Is there any plan to include the lighten() functionality? Maybe any workaround to make it happen?

Nested colors functions

It wasn't clear to me if the css4 colors would support with this or if css4 variables would cause the same issues as postcss-simple-vars.

Source:

// variables.css
$red: #0c0;
$darkred: color($red l(-20%));

// mypage.css
div {
    background: color($darkred a(50%));
}

Output from postcss-simple-vars:

div {
    background: color(color(#0c0 l(-20%)) a(50%));
}

Output from postcss-color-function:

div {
    background: rgba(NaN, NaN, NaN, 128);  // or something like this
}

Opinions? Advice?

Dollar variable inside color adjuster

Finding an issue having the plugin working with dollar variable in a loop.
Combining it with postcss-for, I'm trying to achieve this:

Input:

@for $i from 1 to 3 {
	li:nth-of-type($i) {
		background-color: color( yellow h( calc( $i * 10 ) ) );
		width: calc( $i% * 10 );
	}
}

Expected output:

li:nth-of-type(1) {
	background-color: rgb(255, 43, 0);
	width: calc( 1% * 10 );
}

li:nth-of-type(2) {
	background-color: rgb(255, 85, 0);
	width: calc( 2% * 10 );
}

li:nth-of-type(3) {
	background-color: rgb(255, 128, 0);
	width: calc( 3% * 10 );
}

Instead I get this:

li:nth-of-type(1) {
	background-color: rgb(0, 0, 0);
	width: calc( 1% * 10 );
}

li:nth-of-type(2) {
	background-color: rgb(0, 0, 0);
	width: calc( 2% * 10 );
}

li:nth-of-type(3) {
	background-color: rgb(0, 0, 0);
	width: calc( 3% * 10 );
}

As you can see from width: calc( $i% * 10 ), the dollar variable is looping fine so I reckon it's probably an issue with this plugin.

I also tried h( calc( $(i) * 10 ) ), h( calc( $(i)deg * 10 ) ) and h( calc( $ideg * 10 ) ) instead of just h( calc( $i * 10 ) ) but still not working.

Working wrong with POSTCSS-CUSTOM-PROPERTIES

This is my postcss.config.js

module.exports = {
  plugins: [
    require('postcss-easy-import'),
    require('postcss-mixins'),
    require('postcss-nested'),
    require('postcss-custom-properties'),
    require("postcss-color-function"),
      ]
}

In the precompiled file y write:

.header{
    background-color: color(var(--lightcolor) a(30%));
}

The result is:

.header{
    background-color: rgba(255, 255, 255, 0.3);
    background-color: color(var(--lightcolor) a(30%));
}

The declaration is duplicated, what I did wrong???

the task is:

"scripts": {
    "css": "postcss pcss/style.pcss -o frontend/css/style.css —no-map —verbose"
}

what is missing ???

Thanks for your help friends!!

Need support for `@value` declarations

Problem

Css modules variables values not converted by color function

Example

// index.css
@value transparentBlack: color(#333 a(8%));
//index.js
@import { transparentBlack } from './index.css';

console.log(transparentBlack) 

Intended outcome

rgba(51, 51, 51, 0.36)

Actual outcome

color(#333 a(8%))

Compatibility with other plugins + order of execution.

I'm not quite sure what the problem I am having is, but let me explain my setup and you might be able to provide some insight into why Im experiencing this strange behavior.

I'm using the mixins plugin and the variables plugin. I have colorFunction() at the bottom of my postcss processors.

One of my color variables:

$purple:#852e73;

My mixin

@define-mixin button $color {
    &:hover {
        box-shadow: 0 0 0 3px $color,
        inset 0 0 0 3px $white;
        color: #fff;
    }

    &:active {
       background:color($color blackness(50%));
    }
}

Calling the mixin

@mixin button $purple;

When I run my gulp task I get this error

Error: /assets/src/css/utility/mixins.css:122:9: Unable to parse color from string "$purple"

Why this is weird -
I'm runnning my color function at the end of my postcss processors so it shouldn't even see the string "$purple"

gulp.task('css', function () {
    var postcss         = require('gulp-postcss')
    var sourcemaps      = require('gulp-sourcemaps')
    var nano            = require('gulp-cssnano')
    var colorFunction   = require("postcss-color-function")

    return gulp.src(['./assets/src/css/**/*.css', './assets/src/scss/**/*.scss'])
        .pipe( sourcemaps.init() )
        .pipe( postcss([
            require("postcss-import"),
            require('postcss-mixins'),
            require('postcss-nested'),
            require('postcss-simple-vars')({ silent: true }),
            require('postcss-font-magician')({ hosted: 'assets/build/fonts/' }),
            require('lost'),
            require('autoprefixer'),
            colorFunction(),
        ]))
        .pipe( nano() )
        .pipe( sourcemaps.write('./assets/build/css/') )
        .pipe( gulp.dest('./assets/build/css/') );
});

Even though my gulp task errors out the mixin runs as expected. I can see the correct active state on my button with the correct color manipulation.

If I keep everything as is but remove colorFunction() from my gulp task I can see this as my active state background property:

background:color(#852e73 blackness(50%));

It appears that the colorfunction is somehow finding a way to execute before my other postcss plugins after initially executing in the correct order. Any ideas? Let me know if I can provide more info

Error: assets/src/css/utility/mixins.css:122:9: Unable to parse color from string "$purple"
    at assets/src/css/utility/mixins.css:122:9
    at Object.Color (node_modules/postcss-color-function/node_modules/css-color-function/node_modules/color/index.js:33:10)
    at toRGB (node_modules/postcss-color-function/node_modules/css-color-function/lib/convert.js:39:15)
    at Object.convert (node_modules/postcss-color-function/node_modules/css-color-function/lib/convert.js:28:10)
    at node_modules/postcss-color-function/index.js:38:26
    at walk (node_modules/postcss-color-function/node_modules/postcss-value-parser/lib/walk.js:7:22)
    at ValueParser.walk (node_modules/postcss-color-function/node_modules/postcss-value-parser/lib/index.js:18:5)
    at transformColor (node_modules/postcss-color-function/index.js:33:25)
    at transformColorValue (node_modules/postcss-color-function/index.js:20:16)
    at Object.tryCatch [as try] (node_modules/postcss-color-function/node_modules/postcss-message-helpers/index.js:53:12)
    at transformDecl (node_modules/postcss-color-function/index.js:19:31)
    at node_modules/gulp-postcss/node_modules/postcss/lib/container.js:86:28
    at node_modules/postcss-import/node_modules/postcss/lib/container.js:73:26
    at Rule.each (node_modules/postcss-import/node_modules/postcss/lib/container.js:60:22)
    at Rule.walk (node_modules/postcss-import/node_modules/postcss/lib/container.js:72:21)
    at node_modules/gulp-postcss/node_modules/postcss/lib/container.js:75:32
    at Root.each (node_modules/gulp-postcss/node_modules/postcss/lib/container.js:60:22)

Better docs with examples

We should add better docs with examples for popular user cases like lighten/darken color. Now you need to open W3C spec and it is very bad for quick look. There is no examples or any way to find answer quickly.

For example, some people even think, that plugin didn’t support lighten :).

/cc @MoOx

Can not calculate hue under 0 over 360

Can not calculate hue under 0 over 360.
The CSS color draft says:

The angle 0deg represents red (as does 360deg, 720deg, etc.)

In this sentence we can infer that numbers under 0 over 360 are allowed.

Input:

.a {
    color: color(red hue(-120));
    color: color(red hue(0));
    color: color(red hue(+120));

    color: color(blue hue(-120));
    color: color(blue hue(0));
    color: color(blue hue(+120));
}

Expected:

.a {
    color: rgb(0, 0, 255); /* Green */
    color: rgb(255, 0, 0);
    color: rgb(0, 255, 0);

    color: rgb(0, 255, 0);
    color: rgb(255, 0, 0);
    color: rgb(0, 0, 255); /* Blue */
}

Real:

.a {
    color: rgb(255, 0, 0); /* Expected green but red */
    color: rgb(255, 0, 0);
    color: rgb(0, 255, 0);

    color: rgb(0, 255, 0);
    color: rgb(255, 0, 0);
    color: rgb(255, 0, 0); /* Expected blue but red */
}

Why is this missing from postcss-preset-env?

Hi!

This package looks awesome and I'd like to use it in my day to day! Though, I'm confused about its position in the css world. I see that there are a bunch of browsers that already support this with prefixing (https://www.caniuse.com/#feat=css-color-adjust), so autoprefixer should take care of those, but what about edge/ie? I'm also noticing that it was a part of cssnext.io (http://cssnext.io/features/#color-function) but I don't see it in post-css-env (https://preset-env.cssdb.org/features). What's the status with this?

Thanks!

Howto combine color() and css variables

Hello,

I'd like to combine postcss-color-function and postcss-css-variables in a single declaration:

:root
{   --color-primary: #f00;
    --color-primary-light: color(var(--color-primary) l(50%));
}

This results a fatal error:

 Unable to parse color from string "var(--color-primary)"

Thank you

Unanable to use with custom properties

The plugins fails on custom property as color to transform:

.foo {
     color: color(var(--color) a(.5));
}

It is possible to solve problem to use postcss-custom-properties before postcss-color-fucntion. But it is not good variant if custom properties are used in production.
Also it is a problem when using cssnext with browserslist for modern browsers. It doesn't transform custom properties, but try to transform color function, what cause error.

Color functions not being processed

Beginner question. I'm running PostCSS/postcss-color-function via Gulp and tried a reduction to get to the bottom of my issue. I have this task:

var postcss = require("gulp-postcss"); 
var colorFunction = require("postcss-color-function");

gulp.task("css", function(){
    var processors = [
    colorFunction
        ];
    gulp.src("preCSS/styles.css")
    .pipe(postcss(processors))
    .pipe(gulp.dest("output"));
});

Given this input:

.thing {
   color: color(white a(90%));
}

I am getting this (same) output:

.thing {
   color: color(white a(90%));
}

Is this due to the way I am configuring?

it doesn't work

Platform:Raspberry Pi 2B
OS:Raspbian
NodeJs:v6.11.3
npm:3.10.10
I follow the Usage,installed postcss-color-function,and create index.js
run node index.js
Nothing happened,input.css does not change

Stripping required spaces

#Input:
border-color: color(#111111 l(-5%)) color(#111111 l(-5%)) color(#111111 l(-15%));

#Output:
border-color: rgb(5, 5, 5)rgb(5, 5, 5)rgb(0, 0, 0);

I can repro this in the UI Next playground. I also see this with the webpack CSS Loader and minification disabled.

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.