# rework-vars

> CSS spec style variables for Rework

Latest version **3.1.1** (published 2014-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install rework-vars
pnpm add rework-vars
yarn add rework-vars
bun add rework-vars
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2014-06-20 |
| First published | 2013-06-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 62 |
| Maintainers | tjholowaychuk, necolas |
| Keywords | css, rework, rework-plugin, variables, vars |

## Links

- npm: https://www.npmjs.com/package/rework-vars
- Repository: https://github.com/reworkcss/rework-vars
- Issues: https://github.com/reworkcss/rework-vars/issues
- npm.io page: https://npm.io/package/rework-vars

## Dependencies (2)

- [rework-visit](https://npm.io/package/rework-visit.md) 1.0.0
- [balanced-match](https://npm.io/package/balanced-match.md) ~0.1.0

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 3.1.1 (latest) — 2014-06-20
- 3.1.0 — 2014-06-19
- 3.0.0 — 2014-04-17
- 2.0.3 — 2014-02-11
- 2.0.2 — 2013-12-18
- 2.0.1 — 2013-12-18
- 2.0.0 — 2013-12-18
- 1.1.0 — 2013-12-01
- 1.0.1 — 2013-07-24
- 1.0.0 — 2013-06-19

## README

# rework-vars [![Build Status](https://travis-ci.org/reworkcss/rework-vars.png)](https://travis-ci.org/reworkcss/rework-vars)

A [Rework](https://github.com/reworkcss/rework) plugin to add support for the
[W3C-style CSS variables](http://www.w3.org/TR/css-variables/) syntax.

**N.B.** This is _not_ a polyfill. This plugin aims to provide a future-proof
way of using a _limited subset_ of the features provided by native CSS variables.

## Installation

```
npm install rework-vars
```

## Use

As a Rework plugin:

```js
// dependencies
var fs = require('fs');
var rework = require('rework');
var vars = require('rework-vars');

// css to be processed
var css = fs.readFileSync('build/build.css', 'utf8').toString();

// process css using rework-vars
var options = {};
var out = rework(css).use(vars(options)).toString();
```

### Options

#### `map`

Optionally, you may pass an object of variables - `map` - to the JavaScript
function.

```js
var map = {
  'app-bg-color': 'white'
}

var out = rework(css).use(vars({map: map})).toString();
```

#### `preserve` (default: `false`)

Setting `preserve` to `true` will preserve the variable definitions and
references in the output, so that they can be used by supporting browsers.

```js
var out = rework(css).use(vars({preserve: true})).toString();
```

## Supported features

Variables can be declared as custom CSS properties on the `:root` element,
prefixed with `--`:

```css
:root {
  --my-color: red;
}
```

Variables are applied using the `var()` function, taking the name of a variable
as the first argument:

```css
:root {
  --my-color: red;
}

div {
  color: var(--my-color);
}
```

Fallback values are supported and are applied if a variable has not been
declared:

```css
:root {
  --my-color: red;
}

div {
  color: var(--other-color, green);
}
```

Fallbacks can be "complex". Anything after the first comma in the `var()`
function will act as the fallback value – `var(name, fallback)`. Nested
variables are also supported:

```css
:root {
  --my-color: red;
}

div {
  background: var(--my-other-color, linear-gradient(var(--my-color), rgba(255,0,0,0.5)));
}
```

## What to expect

Variables can _only_ be declared for, and scoped to the `:root` element. All
other variable declarations are left untouched. Any known variables used as
values are replaced.

```css
:root {
  --color-one: red;
  --color-two: green;
}

:root,
div {
  --color-two: purple;
  color: var(--color-two);
}

div {
  --color-three: blue;
}

span {
  --color-four: yellow;
}
```

yields:

```css
:root,
div {
  --color-two: purple;
  color: green;
}

div {
  --color-three: blue;
}

span {
  --color-four: yellow;
}
```

Variables are not dynamic; they are replaced with normal CSS values. The value
of a defined variable is determined by the last declaration of that variable
for `:root`.

```css
:root {
  --brand-color: green;
}

.brand {
  color: var(--brand-color);
}

:root {
  --brand-color: red;
}
```

yields:

```css
.brand {
  color: red;
}
```

Variables declared within `@media` or `@supports` are not currently supported
and will also be ignored.

```css
@media (min-width: 320px) {
  :root {
    --brand-color: red;
  }
}
```

yields:

```css
@media (min-width: 320px) {
  :root {
    --brand-color: red;
  }
}
```

## License

MIT

---
_Source: https://npm.io/package/rework-vars · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
