postcss-color-function

WebJar for postcss-color-function

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

postcss-color-function
Последняя версия

Последняя версия

4.0.1
Дата

Дата

Тип

Тип

jar
Описание

Описание

postcss-color-function
WebJar for postcss-color-function
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/postcss/postcss-color-function

Скачать postcss-color-function

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/postcss-color-function/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>postcss-color-function</artifactId>
    <version>4.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/postcss-color-function/
implementation 'org.webjars.npm:postcss-color-function:4.0.1'
// https://jarcasting.com/artifacts/org.webjars.npm/postcss-color-function/
implementation ("org.webjars.npm:postcss-color-function:4.0.1")
'org.webjars.npm:postcss-color-function:jar:4.0.1'
<dependency org="org.webjars.npm" name="postcss-color-function" rev="4.0.1">
  <artifact name="postcss-color-function" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='postcss-color-function', version='4.0.1')
)
libraryDependencies += "org.webjars.npm" % "postcss-color-function" % "4.0.1"
[org.webjars.npm/postcss-color-function "4.0.1"]

Зависимости

compile (4)

Идентификатор библиотеки Тип Версия
org.webjars.npm : css-color-function jar [1.3.3,1.4)
org.webjars.npm : postcss jar [6.0.1,7)
org.webjars.npm : postcss-message-helpers jar [2.0.0,3)
org.webjars.npm : postcss-value-parser jar [3.3.0,4)

Модули Проекта

Данный проект не имеет модулей.

postcss-color-function Build Status

PostCSS plugin to transform CSS color function from editor draft of 'Color Module Level 4' specification to more compatible CSS.

Deprecated

⚠️ color() was changed to color-mod(). See postcss-color-mod-function.

There is a color-mod implementation.

⚠️ color-mod() has been removed from Color Module Level 4 specification.

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
// set preserveCustomProps to `false` by default `true`
//for delete declarations with custom properties
var output = postcss()
  .use(colorFunction({preserveCustomProps: true}))
  .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.

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.

Notes for former Sass users

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:

$lighten(red, 20%)
/*  is equivalent to */
color(red tint(20%))

$darken(red, 20%)
/*  is equivalent to */
color(red shade(20%))

Changelog

License

org.webjars.npm

PostCSS

PostCSS and plugins based on it

Версии библиотеки

Версия
4.0.1