# postcss-custom-media-with-spaces

> Use Custom Media Queries in CSS

Latest version **8.0.0** (published 2021-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install postcss-custom-media-with-spaces
pnpm add postcss-custom-media-with-spaces
yarn add postcss-custom-media-with-spaces
bun add postcss-custom-media-with-spaces
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2021-11-24 |
| First published | 2020-11-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10.0.0 |
| Dependencies | 0 |
| Unpacked size | 41.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 434 |
| Author | Alex Knyazev |
| Maintainers | alexknyazev |
| Keywords | postcss, css, postcss-plugin, custom, media, query, queries, w3c, csswg, atrule, at-rule, specification |

## Links

- npm: https://www.npmjs.com/package/postcss-custom-media-with-spaces
- Repository: https://github.com/postcss/postcss-custom-media
- Homepage: https://github.com/alex-knyazev/postcss-custom-media/blob/custom-lib/README.md
- Issues: https://github.com/alex-knyazev/postcss-custom-media/issues
- npm.io page: https://npm.io/package/postcss-custom-media-with-spaces

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 8.0.0 (latest) — 2021-11-24
- 7.0.9 — 2020-11-03
- 7.0.8 — 2020-11-03

## README

# PostCSS Custom Media With spaces [<img src="https://postcss.github.io/postcss/logo.svg" alt="PostCSS" width="90" height="90" align="right">][postcss]

[![NPM Version][npm-img]][npm-url]
[![CSS Standard Status][css-img]][css-url]
[![Build Status][cli-img]][cli-url]
[![Support Chat][git-img]][git-url]

[PostCSS Custom Media] lets you use Custom Media Queries in CSS, following the
[CSS Media Queries] specification.

```pcss
@custom-media --small-viewport (max-width: 30em);

@media (--small-viewport) {
  /* styles for small viewport */
}

/* becomes */

@media (max-width: 30em) {
  /* styles for small viewport */
}
```

# IMPORTANT

This project is a fork for https://github.com/postcss/postcss-custom-media to support custom media using with spaces aftel left and before tight brackets:

In original lib you can use only media without brackets:

```
@media (--my-custom-media) {

    #myBlock {
        ...
    }
}

```

Here you can also use it with brackets: 


```
@media ( --my-custom-media ) {

    #myBlock {
      ...
    }
}

```

It is useful when we have deal with stylelint [media-feature-parentheses-space-inside](https://stylelint.io/user-guide/rules/media-feature-parentheses-space-inside#:~:text=Require%20a%20single%20space%20or,the%20parentheses%20within%20media%20features.&text=The%20fix%20option%20can%20automatically,problems%20reported%20by%20this%20rule) rule.

PR is created to ad this to base lib: https://github.com/postcss/postcss-custom-media/pull/59

New tests are created and passed to check that added functionality is worked.

## Usage

Add [PostCSS Custom Media] to your project:

```bash
npm install postcss-custom-media --save-dev
```

Use [PostCSS Custom Media] to process your CSS:

```js
const postcssCustomMedia = require('postcss-custom-media');

postcssCustomMedia.process(YOUR_CSS /*, processOptions, pluginOptions */);
```

Or use it as a [PostCSS] plugin:

```js
const postcss = require('postcss');
const postcssCustomMedia = require('postcss-custom-media');

postcss([
  postcssCustomMedia(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```

[PostCSS Custom Media] runs in all Node environments, with special instructions for:

| [Node](INSTALL.md#node) | [PostCSS CLI](INSTALL.md#postcss-cli) | [Webpack](INSTALL.md#webpack) | [Create React App](INSTALL.md#create-react-app) | [Gulp](INSTALL.md#gulp) | [Grunt](INSTALL.md#grunt) |
| --- | --- | --- | --- | --- | --- |

## Options

### preserve

The `preserve` option determines whether custom media and atrules using custom
media should be preserved in their original form.

```pcss
@custom-media --small-viewport (max-width: 30em);

@media (--small-viewport) {
  /* styles for small viewport */
}

/* becomes */

@custom-media --small-viewport (max-width: 30em);

@media (max-width: 30em) {
  /* styles for small viewport */
}

@media (--small-viewport) {
  /* styles for small viewport */
}
```

### importFrom

The `importFrom` option specifies sources where custom media can be imported
from, which might be CSS, JS, and JSON files, functions, and directly passed
objects.

```js
postcssCustomMedia({
  importFrom: 'path/to/file.css' // => @custom-selector --small-viewport (max-width: 30em);
});
```

```pcss
@media (max-width: 30em) {
  /* styles for small viewport */
}

@media (--small-viewport) {
  /* styles for small viewport */
}
```

Multiple sources can be passed into this option, and they will be parsed in the
order they are received. JavaScript files, JSON files, functions, and objects
will need to namespace custom media using the `customMedia` or
`custom-media` key.

```js
postcssCustomMedia({
  importFrom: [
    'path/to/file.css',
    'and/then/this.js',
    'and/then/that.json',
    {
      customMedia: { '--small-viewport': '(max-width: 30em)' }
    },
    () => {
      const customMedia = { '--small-viewport': '(max-width: 30em)' };

      return { customMedia };
    }
  ]
});
```

### exportTo

The `exportTo` option specifies destinations where custom media can be exported
to, which might be CSS, JS, and JSON files, functions, and directly passed
objects.

```js
postcssCustomMedia({
  exportTo: 'path/to/file.css' // @custom-media --small-viewport (max-width: 30em);
});
```

Multiple destinations can be passed into this option, and they will be parsed
in the order they are received. JavaScript files, JSON files, and objects will
need to namespace custom media using the `customMedia` or
`custom-media` key.

```js
const cachedObject = { customMedia: {} };

postcssCustomMedia({
  exportTo: [
    'path/to/file.css',   // @custom-media --small-viewport (max-width: 30em);
    'and/then/this.js',   // module.exports = { customMedia: { '--small-viewport': '(max-width: 30em)' } }
    'and/then/this.mjs',  // export const customMedia = { '--small-viewport': '(max-width: 30em)' } }
    'and/then/that.json', // { "custom-media": { "--small-viewport": "(max-width: 30em)" } }
    cachedObject,
    customMedia => {
      customMedia    // { '--small-viewport': '(max-width: 30em)' }
    }
  ]
});
```

See example exports written to [CSS](test/export-media.css),
[JS](test/export-media.js), [MJS](test/export-media.mjs), and
[JSON](test/export-media.json).

[cli-img]: https://img.shields.io/travis/postcss/postcss-custom-media/master.svg
[cli-url]: https://travis-ci.org/postcss/postcss-custom-media
[css-img]: https://cssdb.org/badge/custom-media-queries.svg
[css-url]: https://cssdb.org/#custom-media-queries
[git-img]: https://img.shields.io/badge/support-chat-blue.svg
[git-url]: https://gitter.im/postcss/postcss
[npm-img]: https://img.shields.io/npm/v/postcss-custom-media.svg
[npm-url]: https://www.npmjs.com/package/postcss-custom-media

[CSS Media Queries]: https://drafts.csswg.org/mediaqueries-5/#custom-mq
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Custom Media]: https://github.com/postcss/postcss-custom-media

---
_Source: https://npm.io/package/postcss-custom-media-with-spaces · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
