项目作者: polemius

项目描述 :
PostCSS plugin to transform clamp() to combination of min/max
高级语言: JavaScript
项目地址: git://github.com/polemius/postcss-clamp.git
创建时间: 2020-05-03T05:33:37Z
项目社区:https://github.com/polemius/postcss-clamp

开源协议:MIT License

下载


PostCSS Clamp

Build Status codecov.io

PostCSS plugin to transform clamp() to combination of min/max.

This plugin transform this css:

  1. .foo {
  2. width: clamp(10px, 4em, 80px);
  3. }

into this:

  1. .foo {
  2. width: max(10px, min(4em, 80px));
  3. }

Or with enabled options precalculate:

  1. .foo {
  2. width: clamp(10em, 4px, 10px);
  3. }
  4. /* becomes */
  5. .foo {
  6. width: max(10em, 14px);
  7. }

'Can I use' table

Instalation

  1. $ npm install postcss postcss-clamp --save-dev
  2. or
  3. $ yarn add --dev postcss postcss-clamp

Usage

Use PostCSS Clamp as a PostCSS plugin:

  1. const postcss = require('postcss');
  2. const postcssClamp = require('postcss-clamp');
  3. postcss([
  4. postcssClamp(/* pluginOptions */)
  5. ]).process(YOUR_CSS /*, processOptions */);

PostCSS Clamp runs in all Node environments, with special instructions for:

Node PostCSS CLI Webpack Create React App Gulp Grunt

See PostCSS docs for examples for your environment.

Options

precalculate

The precalculate option determines whether values with the same unit
should be precalculated. By default, these are not precalculation.

  1. postcssColorHexAlpha({
  2. precalculate: true
  3. });

The second and third value has the same unit (px):

  1. .foo {
  2. width: clamp(10em, 4px, 10px);
  3. }
  4. /* becomes */
  5. .foo {
  6. width: max(10em, 14px);
  7. }

Here all values have the same unit:

  1. .foo {
  2. width: clamp(10px, 4px, 10px);
  3. }
  4. /* becomes */
  5. .foo {
  6. width: 24px;
  7. }

LICENSE

See LICENSE