0.2.0 - Mid migration

This commit is contained in:
Daniel Mason 2022-04-25 14:47:15 +12:00
parent 139e6a915e
commit 7e38fdbd7d
42393 changed files with 5358157 additions and 62 deletions

207
web/node_modules/postcss-custom-properties/CHANGELOG.md generated vendored Executable file
View file

@ -0,0 +1,207 @@
# Changes to PostCSS Custom Properties
### 8.0.11 (June 20, 2019)
- Added: Synchronous transforms when async is unnecessary (thank @eteeselink)
- Fixed: Unexpected mutations to imported Custom Properties (thank @EECOLOR)
- Fixed: Transforms throwing over unknown Custom Properties
### 8.0.10 (April 1, 2019)
- Added: Support for ignoring lines and or blocks using
`postcss-custom-properties` comments.
- Updated: `postcss` to 7.0.14 (patch)
- Updated: `postcss-values-parser` to 2.0.1 (patch)
### 8.0.9 (November 5, 2018)
- Fixed: Issue with duplicate custom property usage within a declaration
### 8.0.8 (October 2, 2018)
- Fixed: Issue with nested fallbacks
### 8.0.7 (October 2, 2018)
- Fixed: Issue with parsing custom properties that are not strings
- Updated: `postcss` to 7.0.5 (patch)
### 8.0.6 (September 21, 2018)
- Fixed: Issue with regular `:root` and `html` properties not getting polyfilled
- Updated: `postcss` to 7.0.3 (patch)
### 8.0.5 (September 21, 2018)
- Fixed: Issue with multiple `importFrom` not getting combined
### 8.0.4 (September 18, 2018)
- Fixed: Do not break on an empty `importFrom` object
### 8.0.3 (September 18, 2018)
- Updated: PostCSS Values Parser 2
### 8.0.2 (September 17, 2018)
- Fixed: Spacing is preserved before replaced variables.
### 8.0.1 (September 17, 2018)
- Fixed: Workaround issue in `postcss-values-parser` incorrectly cloning nodes.
### 8.0.0 (September 16, 2018)
- Added: New `exportTo` function to specify where to export custom properties to.
- Added: New `importFrom` option to specify where to import custom properties from.
- Added: Support for variables written within `html`
- Added: Support for PostCSS v7.
- Added: Support for Node v6+.
- Removed: `strict` option, as using the fallback value isnt necessarily more valid.
- Removed: `preserve: "computed"` option, as there seems to be little use in preserving custom property declarations while removing all usages of them.
- Removed: `warnings` and `noValueNotifications` options, as this should be the job of a linter tool.
- Removed: `variables` option, which is now replaced by `importFrom`
- Removed: `appendVariables` option, which is now replaced by `exportTo`
- Fixed: Custom Properties in `:root` are not also transformed.
- Fixed: Declarations that do not change are not duplicated during preserve.
### 7.0.0 (February 16, 2018)
- Changed: `preserve` option defaults as `true` to reflect the browser climate
- Changed: `warnings` option defaults to `false` to reflect the browser climate
### 6.3.1 (February 16, 2018)
- Reverted: `preserve` and `warnings` option to be added in major release
### 6.3.0 (February 15, 2018)
- Fixed: `var()` captures strictly `var()` functions and not `xvar()`, etc
- Fixed: `var()` better captures whitespace within the function
- Fixed: comments within declarations using `var()` are now preserved
- Changed: `preserve` option defaults as `true` to reflect the browser climate
- Changed: `warnings` option defaults to `false` to reflect the browser climate
- Updated documentation
### 6.2.0 (October 6, 2017)
- Added: `noValueNotifications` option (#71)
- Fixed: Typo in `prefixedVariables` variable name (#77)
### 6.1.0 (June 28, 2017)
- Added: Let "warnings" option silence all warnings
([#67](https://github.com/postcss/postcss-custom-properties/pull/67))
- Dependencies update (postcss, balanced-match)
### 6.0.1 (May 15, 2017)
- Fixed: incorrect export ([#69](https://github.com/postcss/postcss-custom-properties/issues/69))
### 6.0.0 (May 12, 2017)
- Added: compatibility with postcss v6.x
### 5.0.2 (February 1, 2017)
- Minor dependency update
([#57](https://github.com/postcss/postcss-custom-properties/pull/57))
### 5.0.1 (April 22, 2016)
- Fixed: trailing space after custom property name causes duplicate empty
property
([#43](https://github.com/postcss/postcss-custom-properties/pull/43))
### 5.0.0 (August 25, 2015)
- Removed: compatibility with postcss v4.x
- Added: compatibility with postcss v5.x
### 4.2.0 (July 21, 2015)
- Added: `warnings` option allows you to disable warnings.
([cssnext#186](https://github.com/cssnext/cssnext/issues/186))
### 4.1.0 (July 14, 2015)
- Added: plugin now returns itself in order to expose a `setVariables` function
that allow you to programmatically change the variables.
([#35](https://github.com/postcss/postcss-custom-properties/pull/35))
### 4.0.0 (June 17, 2015)
- Changed: messages and exceptions are now sent using postcss message API.
### 3.3.0 (April 8, 2015)
- Added: `preserve` now support `"computed"` so only preserve resolved custom properties (see new option below)
- Added: `appendVariables` allows you (when `preserve` is truthy) to append your variables as custom properties
- Added: `strict: false` allows your to avoid too many fallbacks added in your CSS.
### 3.2.0 (03 31, 2015)
- Added: JS defined variables are now resolved too ([#22](https://github.com/postcss/postcss-custom-properties/issues/22))
### 3.1.0 (03 16, 2015)
- Added: variables defined in JS are now automatically prefixed with `--`
([0691784](https://github.com/postcss/postcss-custom-properties/commit/0691784ed2218d7e6b16da8c4df03e2ca0c4798c))
### 3.0.1 (February 6, 2015)
- Fixed: logs now have filename back ([#19](https://github.com/postcss/postcss-custom-properties/issues/19))
### 3.0.0 (January 20, 2015)
- Changed: upgrade to postcss 4 ([#18](https://github.com/postcss/postcss-custom-properties/pull/18))
- Removed: some code that seems to be useless ([16ff3c2](https://github.com/postcss/postcss-custom-properties/commit/16ff3c22fe0563a1283411d7866791966fff4c58))
### 2.1.1 (December 2, 2014)
- Fixed: issue when multiples undefined custom properties are referenced ([#16](https://github.com/postcss/postcss-custom-properties/issues/16))
### 2.1.0 (November 25, 2014)
- Added: enhanced exceptions & messages
### 2.0.0 (November 12, 2014)
- Changed: upgrade to postcss 3
### 1.0.2 (November 4, 2014)
- Fixed: more clear message for warning about custom prop used in non top-level :root
### 1.0.1 (November 3, 2014)
- Fixed: warning about custom prop used in non :root
### 1.0.0 (November 2, 2014)
- Added: warning when a custom prop is used in another place than :root
- Added: handle !important
### 0.4.0 (September 30, 2014)
- Added: JS-defined properties override CSS-defined
### 0.3.1 (August 27, 2014)
- Added: nested custom properties usages are now correctly resolved
- Changed: undefined var doesn't throw error anymore (just a console warning) & are kept as is in the output
### 0.3.0 (August 26, 2014)
- Changed: fallback now are always added by default ([see why](http://www.w3.org/TR/css-variables/#invalid-variables))
- Changed: `map` option renamed to `variables`
### 0.2.0 (August 22, 2014)
- Added: `map` option
- Changed: GNU style error message
### 0.1.0 (August 1, 2014)
✨ First release based on [rework-vars](https://github.com/reworkcss/rework-vars) v3.1.1

21
web/node_modules/postcss-custom-properties/LICENSE.md generated vendored Normal file
View file

@ -0,0 +1,21 @@
# The MIT License (MIT)
Copyright © PostCSS
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

193
web/node_modules/postcss-custom-properties/README.md generated vendored Executable file
View file

@ -0,0 +1,193 @@
# PostCSS Custom Properties [<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 Properties] lets you use Custom Properties in CSS, following
the [CSS Custom Properties] specification.
```pcss
:root {
--color: red;
}
h1 {
color: var(--color);
}
/* becomes */
:root {
--color: red;
}
h1 {
color: red;
color: var(--color);
}
```
## Usage
Add [PostCSS Custom Properties] to your project:
```bash
npm install postcss-custom-properties --save-dev
```
Use [PostCSS Custom Properties] to process your CSS:
```js
const postcssCustomProperties = require('postcss-custom-properties');
postcssCustomProperties.process(YOUR_CSS /*, processOptions, pluginOptions */);
```
Or use it as a [PostCSS] plugin:
```js
const postcss = require('postcss');
const postcssCustomProperties = require('postcss-custom-properties');
postcss([
postcssCustomProperties(/* pluginOptions */)
]).process(YOUR_CSS /*, processOptions */);
```
[PostCSS Custom Properties] 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 Properties and properties using
custom properties should be preserved in their original form. By default, both
of these are preserved.
```js
postcssCustomProperties({
preserve: false
});
```
```pcss
:root {
--color: red;
}
h1 {
color: var(--color);
}
/* becomes */
h1 {
color: red;
}
```
### importFrom
The `importFrom` option specifies sources where Custom Properties can be imported
from, which might be CSS, JS, and JSON files, functions, and directly passed
objects.
```js
postcssCustomProperties({
importFrom: 'path/to/file.css' // => :root { --color: red }
});
```
```pcss
h1 {
color: var(--color);
}
/* becomes */
h1 {
color: red;
}
```
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 Properties using the `customProperties` or
`custom-properties` key.
```js
postcssCustomProperties({
importFrom: [
'path/to/file.css', // :root { --color: red; }
'and/then/this.js', // module.exports = { customProperties: { '--color': 'red' } }
'and/then/that.json', // { "custom-properties": { "--color": "red" } }
{
customProperties: { '--color': 'red' }
},
() => {
const customProperties = { '--color': 'red' };
return { customProperties };
}
]
});
```
See example imports written in [CSS](test/import-properties.css),
[JS](test/import-properties.js), and [JSON](test/import-properties.json).
### exportTo
The `exportTo` option specifies destinations where Custom Properties can be exported
to, which might be CSS, JS, and JSON files, functions, and directly passed
objects.
```js
postcssCustomProperties({
exportTo: 'path/to/file.css' // :root { --color: red; }
});
```
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 Properties using the `customProperties` or
`custom-properties` key.
```js
const cachedObject = { customProperties: {} };
postcssCustomProperties({
exportTo: [
'path/to/file.css', // :root { --color: red; }
'and/then/this.js', // module.exports = { customProperties: { '--color': 'red' } }
'and/then/this.mjs', // export const customProperties = { '--color': 'red' } }
'and/then/that.json', // { "custom-properties": { "--color": "red" } }
cachedObject,
customProperties => {
customProperties // { '--color': 'red' }
}
]
});
```
See example exports written to [CSS](test/export-properties.css),
[JS](test/export-properties.js), [MJS](test/export-properties.mjs), and
[JSON](test/export-properties.json).
[cli-img]: https://img.shields.io/travis/postcss/postcss-custom-properties/master.svg
[cli-url]: https://travis-ci.org/postcss/postcss-custom-properties
[css-img]: https://cssdb.org/badge/custom-properties.svg
[css-url]: https://cssdb.org/#custom-properties
[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-properties.svg
[npm-url]: https://www.npmjs.com/package/postcss-custom-properties
[CSS Custom Properties]: https://www.w3.org/TR/css-variables-1/
[PostCSS]: https://github.com/postcss/postcss
[PostCSS Custom Properties]: https://github.com/postcss/postcss-custom-properties

552
web/node_modules/postcss-custom-properties/index.cjs.js generated vendored Normal file
View file

@ -0,0 +1,552 @@
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var postcss = _interopDefault(require('postcss'));
var valueParser = _interopDefault(require('postcss-values-parser'));
var fs = _interopDefault(require('fs'));
var path = _interopDefault(require('path'));
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function parse(string) {
return valueParser(string).parse();
}
function isBlockIgnored(ruleOrDeclaration) {
var rule = ruleOrDeclaration.selector ? ruleOrDeclaration : ruleOrDeclaration.parent;
return /(!\s*)?postcss-custom-properties:\s*off\b/i.test(rule.toString());
}
function isRuleIgnored(rule) {
var previous = rule.prev();
return Boolean(isBlockIgnored(rule) || previous && previous.type === 'comment' && /(!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i.test(previous.text));
}
function getCustomPropertiesFromRoot(root, opts) {
// initialize custom selectors
const customPropertiesFromHtmlElement = {};
const customPropertiesFromRootPseudo = {}; // for each html or :root rule
root.nodes.slice().forEach(rule => {
const customPropertiesObject = isHtmlRule(rule) ? customPropertiesFromHtmlElement : isRootRule(rule) ? customPropertiesFromRootPseudo : null; // for each custom property
if (customPropertiesObject) {
rule.nodes.slice().forEach(decl => {
if (isCustomDecl(decl) && !isBlockIgnored(decl)) {
const prop = decl.prop; // write the parsed value to the custom property
customPropertiesObject[prop] = parse(decl.value).nodes; // conditionally remove the custom property declaration
if (!opts.preserve) {
decl.remove();
}
}
}); // conditionally remove the empty html or :root rule
if (!opts.preserve && isEmptyParent(rule) && !isBlockIgnored(rule)) {
rule.remove();
}
}
}); // return all custom properties, preferring :root properties over html properties
return Object.assign({}, customPropertiesFromHtmlElement, customPropertiesFromRootPseudo);
} // match html and :root rules
const htmlSelectorRegExp = /^html$/i;
const rootSelectorRegExp = /^:root$/i;
const customPropertyRegExp = /^--[A-z][\w-]*$/; // whether the node is an html or :root rule
const isHtmlRule = node => node.type === 'rule' && htmlSelectorRegExp.test(node.selector) && Object(node.nodes).length;
const isRootRule = node => node.type === 'rule' && rootSelectorRegExp.test(node.selector) && Object(node.nodes).length; // whether the node is an custom property
const isCustomDecl = node => node.type === 'decl' && customPropertyRegExp.test(node.prop); // whether the node is a parent without children
const isEmptyParent = node => Object(node.nodes).length === 0;
/* Get Custom Properties from CSS File
/* ========================================================================== */
function getCustomPropertiesFromCSSFile(_x) {
return _getCustomPropertiesFromCSSFile.apply(this, arguments);
}
/* Get Custom Properties from Object
/* ========================================================================== */
function _getCustomPropertiesFromCSSFile() {
_getCustomPropertiesFromCSSFile = _asyncToGenerator(function* (from) {
const css = yield readFile(from);
const root = postcss.parse(css, {
from
});
return getCustomPropertiesFromRoot(root, {
preserve: true
});
});
return _getCustomPropertiesFromCSSFile.apply(this, arguments);
}
function getCustomPropertiesFromObject(object) {
const customProperties = Object.assign({}, Object(object).customProperties, Object(object)['custom-properties']);
for (const key in customProperties) {
customProperties[key] = parse(String(customProperties[key])).nodes;
}
return customProperties;
}
/* Get Custom Properties from JSON file
/* ========================================================================== */
function getCustomPropertiesFromJSONFile(_x2) {
return _getCustomPropertiesFromJSONFile.apply(this, arguments);
}
/* Get Custom Properties from JS file
/* ========================================================================== */
function _getCustomPropertiesFromJSONFile() {
_getCustomPropertiesFromJSONFile = _asyncToGenerator(function* (from) {
const object = yield readJSON(from);
return getCustomPropertiesFromObject(object);
});
return _getCustomPropertiesFromJSONFile.apply(this, arguments);
}
function getCustomPropertiesFromJSFile(_x3) {
return _getCustomPropertiesFromJSFile.apply(this, arguments);
}
/* Get Custom Properties from Imports
/* ========================================================================== */
function _getCustomPropertiesFromJSFile() {
_getCustomPropertiesFromJSFile = _asyncToGenerator(function* (from) {
const object = yield Promise.resolve(require(from));
return getCustomPropertiesFromObject(object);
});
return _getCustomPropertiesFromJSFile.apply(this, arguments);
}
function getCustomPropertiesFromImports(sources) {
return sources.map(source => {
if (source instanceof Promise) {
return source;
} else if (source instanceof Function) {
return source();
} // read the source as an object
const opts = source === Object(source) ? source : {
from: String(source)
}; // skip objects with Custom Properties
if (opts.customProperties || opts['custom-properties']) {
return opts;
} // source pathname
const from = path.resolve(String(opts.from || '')); // type of file being read from
const type = (opts.type || path.extname(from).slice(1)).toLowerCase();
return {
type,
from
};
}).reduce(
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (customProperties, source) {
const _ref2 = yield source,
type = _ref2.type,
from = _ref2.from;
if (type === 'css') {
return Object.assign((yield customProperties), (yield getCustomPropertiesFromCSSFile(from)));
}
if (type === 'js') {
return Object.assign((yield customProperties), (yield getCustomPropertiesFromJSFile(from)));
}
if (type === 'json') {
return Object.assign((yield customProperties), (yield getCustomPropertiesFromJSONFile(from)));
}
return Object.assign((yield customProperties), (yield getCustomPropertiesFromObject((yield source))));
});
return function (_x4, _x5) {
return _ref.apply(this, arguments);
};
}(), {});
}
/* Helper utilities
/* ========================================================================== */
const readFile = from => new Promise((resolve, reject) => {
fs.readFile(from, 'utf8', (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
const readJSON =
/*#__PURE__*/
function () {
var _ref3 = _asyncToGenerator(function* (from) {
return JSON.parse((yield readFile(from)));
});
return function readJSON(_x6) {
return _ref3.apply(this, arguments);
};
}();
function transformValueAST(root, customProperties) {
if (root.nodes && root.nodes.length) {
root.nodes.slice().forEach(child => {
if (isVarFunction(child)) {
// eslint-disable-next-line no-unused-vars
const _child$nodes$slice = child.nodes.slice(1, -1),
propertyNode = _child$nodes$slice[0],
comma = _child$nodes$slice[1],
fallbacks = _child$nodes$slice.slice(2);
const name = propertyNode.value;
if (name in Object(customProperties)) {
// conditionally replace a known custom property
const nodes = asClonedArrayWithBeforeSpacing(customProperties[name], child.raws.before);
child.replaceWith(...nodes);
retransformValueAST({
nodes
}, customProperties, name);
} else if (fallbacks.length) {
// conditionally replace a custom property with a fallback
const index = root.nodes.indexOf(child);
if (index !== -1) {
root.nodes.splice(index, 1, ...asClonedArrayWithBeforeSpacing(fallbacks, child.raws.before));
}
transformValueAST(root, customProperties);
}
} else {
transformValueAST(child, customProperties);
}
});
}
return root;
} // retransform the current ast without a custom property (to prevent recursion)
function retransformValueAST(root, customProperties, withoutProperty) {
const nextCustomProperties = Object.assign({}, customProperties);
delete nextCustomProperties[withoutProperty];
return transformValueAST(root, nextCustomProperties);
} // match var() functions
const varRegExp = /^var$/i; // whether the node is a var() function
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.value) && Object(node.nodes).length > 0; // return an array with its nodes cloned, preserving the raw
const asClonedArrayWithBeforeSpacing = (array, beforeSpacing) => {
const clonedArray = asClonedArray(array, null);
if (clonedArray[0]) {
clonedArray[0].raws.before = beforeSpacing;
}
return clonedArray;
}; // return an array with its nodes cloned
const asClonedArray = (array, parent) => array.map(node => asClonedNode(node, parent)); // return a cloned node
const asClonedNode = (node, parent) => {
const cloneNode = new node.constructor(node);
for (const key in node) {
if (key === 'parent') {
cloneNode.parent = parent;
} else if (Object(node[key]).constructor === Array) {
cloneNode[key] = asClonedArray(node.nodes, cloneNode);
} else if (Object(node[key]).constructor === Object) {
cloneNode[key] = Object.assign({}, node[key]);
}
}
return cloneNode;
};
var transformProperties = ((root, customProperties, opts) => {
// walk decls that can be transformed
root.walkDecls(decl => {
if (isTransformableDecl(decl) && !isRuleIgnored(decl)) {
const originalValue = decl.value;
const valueAST = parse(originalValue);
const value = String(transformValueAST(valueAST, customProperties)); // conditionally transform values that have changed
if (value !== originalValue) {
if (opts.preserve) {
decl.cloneBefore({
value
});
} else {
decl.value = value;
}
}
}
});
}); // match custom properties
const customPropertyRegExp$1 = /^--[A-z][\w-]*$/; // match custom property inclusions
const customPropertiesRegExp = /(^|[^\w-])var\([\W\w]+\)/; // whether the declaration should be potentially transformed
const isTransformableDecl = decl => !customPropertyRegExp$1.test(decl.prop) && customPropertiesRegExp.test(decl.value);
/* Write Custom Properties to CSS File
/* ========================================================================== */
function writeCustomPropertiesToCssFile(_x, _x2) {
return _writeCustomPropertiesToCssFile.apply(this, arguments);
}
/* Write Custom Properties to JSON file
/* ========================================================================== */
function _writeCustomPropertiesToCssFile() {
_writeCustomPropertiesToCssFile = _asyncToGenerator(function* (to, customProperties) {
const cssContent = Object.keys(customProperties).reduce((cssLines, name) => {
cssLines.push(`\t${name}: ${customProperties[name]};`);
return cssLines;
}, []).join('\n');
const css = `:root {\n${cssContent}\n}\n`;
yield writeFile(to, css);
});
return _writeCustomPropertiesToCssFile.apply(this, arguments);
}
function writeCustomPropertiesToJsonFile(_x3, _x4) {
return _writeCustomPropertiesToJsonFile.apply(this, arguments);
}
/* Write Custom Properties to Common JS file
/* ========================================================================== */
function _writeCustomPropertiesToJsonFile() {
_writeCustomPropertiesToJsonFile = _asyncToGenerator(function* (to, customProperties) {
const jsonContent = JSON.stringify({
'custom-properties': customProperties
}, null, ' ');
const json = `${jsonContent}\n`;
yield writeFile(to, json);
});
return _writeCustomPropertiesToJsonFile.apply(this, arguments);
}
function writeCustomPropertiesToCjsFile(_x5, _x6) {
return _writeCustomPropertiesToCjsFile.apply(this, arguments);
}
/* Write Custom Properties to Module JS file
/* ========================================================================== */
function _writeCustomPropertiesToCjsFile() {
_writeCustomPropertiesToCjsFile = _asyncToGenerator(function* (to, customProperties) {
const jsContents = Object.keys(customProperties).reduce((jsLines, name) => {
jsLines.push(`\t\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`);
return jsLines;
}, []).join(',\n');
const js = `module.exports = {\n\tcustomProperties: {\n${jsContents}\n\t}\n};\n`;
yield writeFile(to, js);
});
return _writeCustomPropertiesToCjsFile.apply(this, arguments);
}
function writeCustomPropertiesToMjsFile(_x7, _x8) {
return _writeCustomPropertiesToMjsFile.apply(this, arguments);
}
/* Write Custom Properties to Exports
/* ========================================================================== */
function _writeCustomPropertiesToMjsFile() {
_writeCustomPropertiesToMjsFile = _asyncToGenerator(function* (to, customProperties) {
const mjsContents = Object.keys(customProperties).reduce((mjsLines, name) => {
mjsLines.push(`\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`);
return mjsLines;
}, []).join(',\n');
const mjs = `export const customProperties = {\n${mjsContents}\n};\n`;
yield writeFile(to, mjs);
});
return _writeCustomPropertiesToMjsFile.apply(this, arguments);
}
function writeCustomPropertiesToExports(customProperties, destinations) {
return Promise.all(destinations.map(
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (destination) {
if (destination instanceof Function) {
yield destination(defaultCustomPropertiesToJSON(customProperties));
} else {
// read the destination as an object
const opts = destination === Object(destination) ? destination : {
to: String(destination)
}; // transformer for Custom Properties into a JSON-compatible object
const toJSON = opts.toJSON || defaultCustomPropertiesToJSON;
if ('customProperties' in opts) {
// write directly to an object as customProperties
opts.customProperties = toJSON(customProperties);
} else if ('custom-properties' in opts) {
// write directly to an object as custom-properties
opts['custom-properties'] = toJSON(customProperties);
} else {
// destination pathname
const to = String(opts.to || ''); // type of file being written to
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); // transformed Custom Properties
const customPropertiesJSON = toJSON(customProperties);
if (type === 'css') {
yield writeCustomPropertiesToCssFile(to, customPropertiesJSON);
}
if (type === 'js') {
yield writeCustomPropertiesToCjsFile(to, customPropertiesJSON);
}
if (type === 'json') {
yield writeCustomPropertiesToJsonFile(to, customPropertiesJSON);
}
if (type === 'mjs') {
yield writeCustomPropertiesToMjsFile(to, customPropertiesJSON);
}
}
}
});
return function (_x9) {
return _ref.apply(this, arguments);
};
}()));
}
/* Helper utilities
/* ========================================================================== */
const defaultCustomPropertiesToJSON = customProperties => {
return Object.keys(customProperties).reduce((customPropertiesJSON, key) => {
customPropertiesJSON[key] = String(customProperties[key]);
return customPropertiesJSON;
}, {});
};
const writeFile = (to, text) => new Promise((resolve, reject) => {
fs.writeFile(to, text, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
const escapeForJS = string => string.replace(/\\([\s\S])|(')/g, '\\$1$2').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
var index = postcss.plugin('postcss-custom-properties', opts => {
// whether to preserve custom selectors and rules using them
const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true; // sources to import custom selectors from
const importFrom = [].concat(Object(opts).importFrom || []); // destinations to export custom selectors to
const exportTo = [].concat(Object(opts).exportTo || []); // promise any custom selectors are imported
const customPropertiesPromise = getCustomPropertiesFromImports(importFrom); // synchronous transform
const syncTransform = root => {
const customProperties = getCustomPropertiesFromRoot(root, {
preserve
});
transformProperties(root, customProperties, {
preserve
});
}; // asynchronous transform
const asyncTransform =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (root) {
const customProperties = Object.assign({}, (yield customPropertiesPromise), getCustomPropertiesFromRoot(root, {
preserve
}));
yield writeCustomPropertiesToExports(customProperties, exportTo);
transformProperties(root, customProperties, {
preserve
});
});
return function asyncTransform(_x) {
return _ref.apply(this, arguments);
};
}(); // whether to return synchronous function if no asynchronous operations are requested
const canReturnSyncFunction = importFrom.length === 0 && exportTo.length === 0;
return canReturnSyncFunction ? syncTransform : asyncTransform;
});
module.exports = index;
//# sourceMappingURL=index.cjs.js.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,548 @@
import postcss from 'postcss';
import valueParser from 'postcss-values-parser';
import fs from 'fs';
import path from 'path';
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function parse(string) {
return valueParser(string).parse();
}
function isBlockIgnored(ruleOrDeclaration) {
var rule = ruleOrDeclaration.selector ? ruleOrDeclaration : ruleOrDeclaration.parent;
return /(!\s*)?postcss-custom-properties:\s*off\b/i.test(rule.toString());
}
function isRuleIgnored(rule) {
var previous = rule.prev();
return Boolean(isBlockIgnored(rule) || previous && previous.type === 'comment' && /(!\s*)?postcss-custom-properties:\s*ignore\s+next\b/i.test(previous.text));
}
function getCustomPropertiesFromRoot(root, opts) {
// initialize custom selectors
const customPropertiesFromHtmlElement = {};
const customPropertiesFromRootPseudo = {}; // for each html or :root rule
root.nodes.slice().forEach(rule => {
const customPropertiesObject = isHtmlRule(rule) ? customPropertiesFromHtmlElement : isRootRule(rule) ? customPropertiesFromRootPseudo : null; // for each custom property
if (customPropertiesObject) {
rule.nodes.slice().forEach(decl => {
if (isCustomDecl(decl) && !isBlockIgnored(decl)) {
const prop = decl.prop; // write the parsed value to the custom property
customPropertiesObject[prop] = parse(decl.value).nodes; // conditionally remove the custom property declaration
if (!opts.preserve) {
decl.remove();
}
}
}); // conditionally remove the empty html or :root rule
if (!opts.preserve && isEmptyParent(rule) && !isBlockIgnored(rule)) {
rule.remove();
}
}
}); // return all custom properties, preferring :root properties over html properties
return Object.assign({}, customPropertiesFromHtmlElement, customPropertiesFromRootPseudo);
} // match html and :root rules
const htmlSelectorRegExp = /^html$/i;
const rootSelectorRegExp = /^:root$/i;
const customPropertyRegExp = /^--[A-z][\w-]*$/; // whether the node is an html or :root rule
const isHtmlRule = node => node.type === 'rule' && htmlSelectorRegExp.test(node.selector) && Object(node.nodes).length;
const isRootRule = node => node.type === 'rule' && rootSelectorRegExp.test(node.selector) && Object(node.nodes).length; // whether the node is an custom property
const isCustomDecl = node => node.type === 'decl' && customPropertyRegExp.test(node.prop); // whether the node is a parent without children
const isEmptyParent = node => Object(node.nodes).length === 0;
/* Get Custom Properties from CSS File
/* ========================================================================== */
function getCustomPropertiesFromCSSFile(_x) {
return _getCustomPropertiesFromCSSFile.apply(this, arguments);
}
/* Get Custom Properties from Object
/* ========================================================================== */
function _getCustomPropertiesFromCSSFile() {
_getCustomPropertiesFromCSSFile = _asyncToGenerator(function* (from) {
const css = yield readFile(from);
const root = postcss.parse(css, {
from
});
return getCustomPropertiesFromRoot(root, {
preserve: true
});
});
return _getCustomPropertiesFromCSSFile.apply(this, arguments);
}
function getCustomPropertiesFromObject(object) {
const customProperties = Object.assign({}, Object(object).customProperties, Object(object)['custom-properties']);
for (const key in customProperties) {
customProperties[key] = parse(String(customProperties[key])).nodes;
}
return customProperties;
}
/* Get Custom Properties from JSON file
/* ========================================================================== */
function getCustomPropertiesFromJSONFile(_x2) {
return _getCustomPropertiesFromJSONFile.apply(this, arguments);
}
/* Get Custom Properties from JS file
/* ========================================================================== */
function _getCustomPropertiesFromJSONFile() {
_getCustomPropertiesFromJSONFile = _asyncToGenerator(function* (from) {
const object = yield readJSON(from);
return getCustomPropertiesFromObject(object);
});
return _getCustomPropertiesFromJSONFile.apply(this, arguments);
}
function getCustomPropertiesFromJSFile(_x3) {
return _getCustomPropertiesFromJSFile.apply(this, arguments);
}
/* Get Custom Properties from Imports
/* ========================================================================== */
function _getCustomPropertiesFromJSFile() {
_getCustomPropertiesFromJSFile = _asyncToGenerator(function* (from) {
const object = yield import(from);
return getCustomPropertiesFromObject(object);
});
return _getCustomPropertiesFromJSFile.apply(this, arguments);
}
function getCustomPropertiesFromImports(sources) {
return sources.map(source => {
if (source instanceof Promise) {
return source;
} else if (source instanceof Function) {
return source();
} // read the source as an object
const opts = source === Object(source) ? source : {
from: String(source)
}; // skip objects with Custom Properties
if (opts.customProperties || opts['custom-properties']) {
return opts;
} // source pathname
const from = path.resolve(String(opts.from || '')); // type of file being read from
const type = (opts.type || path.extname(from).slice(1)).toLowerCase();
return {
type,
from
};
}).reduce(
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (customProperties, source) {
const _ref2 = yield source,
type = _ref2.type,
from = _ref2.from;
if (type === 'css') {
return Object.assign((yield customProperties), (yield getCustomPropertiesFromCSSFile(from)));
}
if (type === 'js') {
return Object.assign((yield customProperties), (yield getCustomPropertiesFromJSFile(from)));
}
if (type === 'json') {
return Object.assign((yield customProperties), (yield getCustomPropertiesFromJSONFile(from)));
}
return Object.assign((yield customProperties), (yield getCustomPropertiesFromObject((yield source))));
});
return function (_x4, _x5) {
return _ref.apply(this, arguments);
};
}(), {});
}
/* Helper utilities
/* ========================================================================== */
const readFile = from => new Promise((resolve, reject) => {
fs.readFile(from, 'utf8', (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
const readJSON =
/*#__PURE__*/
function () {
var _ref3 = _asyncToGenerator(function* (from) {
return JSON.parse((yield readFile(from)));
});
return function readJSON(_x6) {
return _ref3.apply(this, arguments);
};
}();
function transformValueAST(root, customProperties) {
if (root.nodes && root.nodes.length) {
root.nodes.slice().forEach(child => {
if (isVarFunction(child)) {
// eslint-disable-next-line no-unused-vars
const _child$nodes$slice = child.nodes.slice(1, -1),
propertyNode = _child$nodes$slice[0],
comma = _child$nodes$slice[1],
fallbacks = _child$nodes$slice.slice(2);
const name = propertyNode.value;
if (name in Object(customProperties)) {
// conditionally replace a known custom property
const nodes = asClonedArrayWithBeforeSpacing(customProperties[name], child.raws.before);
child.replaceWith(...nodes);
retransformValueAST({
nodes
}, customProperties, name);
} else if (fallbacks.length) {
// conditionally replace a custom property with a fallback
const index = root.nodes.indexOf(child);
if (index !== -1) {
root.nodes.splice(index, 1, ...asClonedArrayWithBeforeSpacing(fallbacks, child.raws.before));
}
transformValueAST(root, customProperties);
}
} else {
transformValueAST(child, customProperties);
}
});
}
return root;
} // retransform the current ast without a custom property (to prevent recursion)
function retransformValueAST(root, customProperties, withoutProperty) {
const nextCustomProperties = Object.assign({}, customProperties);
delete nextCustomProperties[withoutProperty];
return transformValueAST(root, nextCustomProperties);
} // match var() functions
const varRegExp = /^var$/i; // whether the node is a var() function
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.value) && Object(node.nodes).length > 0; // return an array with its nodes cloned, preserving the raw
const asClonedArrayWithBeforeSpacing = (array, beforeSpacing) => {
const clonedArray = asClonedArray(array, null);
if (clonedArray[0]) {
clonedArray[0].raws.before = beforeSpacing;
}
return clonedArray;
}; // return an array with its nodes cloned
const asClonedArray = (array, parent) => array.map(node => asClonedNode(node, parent)); // return a cloned node
const asClonedNode = (node, parent) => {
const cloneNode = new node.constructor(node);
for (const key in node) {
if (key === 'parent') {
cloneNode.parent = parent;
} else if (Object(node[key]).constructor === Array) {
cloneNode[key] = asClonedArray(node.nodes, cloneNode);
} else if (Object(node[key]).constructor === Object) {
cloneNode[key] = Object.assign({}, node[key]);
}
}
return cloneNode;
};
var transformProperties = ((root, customProperties, opts) => {
// walk decls that can be transformed
root.walkDecls(decl => {
if (isTransformableDecl(decl) && !isRuleIgnored(decl)) {
const originalValue = decl.value;
const valueAST = parse(originalValue);
const value = String(transformValueAST(valueAST, customProperties)); // conditionally transform values that have changed
if (value !== originalValue) {
if (opts.preserve) {
decl.cloneBefore({
value
});
} else {
decl.value = value;
}
}
}
});
}); // match custom properties
const customPropertyRegExp$1 = /^--[A-z][\w-]*$/; // match custom property inclusions
const customPropertiesRegExp = /(^|[^\w-])var\([\W\w]+\)/; // whether the declaration should be potentially transformed
const isTransformableDecl = decl => !customPropertyRegExp$1.test(decl.prop) && customPropertiesRegExp.test(decl.value);
/* Write Custom Properties to CSS File
/* ========================================================================== */
function writeCustomPropertiesToCssFile(_x, _x2) {
return _writeCustomPropertiesToCssFile.apply(this, arguments);
}
/* Write Custom Properties to JSON file
/* ========================================================================== */
function _writeCustomPropertiesToCssFile() {
_writeCustomPropertiesToCssFile = _asyncToGenerator(function* (to, customProperties) {
const cssContent = Object.keys(customProperties).reduce((cssLines, name) => {
cssLines.push(`\t${name}: ${customProperties[name]};`);
return cssLines;
}, []).join('\n');
const css = `:root {\n${cssContent}\n}\n`;
yield writeFile(to, css);
});
return _writeCustomPropertiesToCssFile.apply(this, arguments);
}
function writeCustomPropertiesToJsonFile(_x3, _x4) {
return _writeCustomPropertiesToJsonFile.apply(this, arguments);
}
/* Write Custom Properties to Common JS file
/* ========================================================================== */
function _writeCustomPropertiesToJsonFile() {
_writeCustomPropertiesToJsonFile = _asyncToGenerator(function* (to, customProperties) {
const jsonContent = JSON.stringify({
'custom-properties': customProperties
}, null, ' ');
const json = `${jsonContent}\n`;
yield writeFile(to, json);
});
return _writeCustomPropertiesToJsonFile.apply(this, arguments);
}
function writeCustomPropertiesToCjsFile(_x5, _x6) {
return _writeCustomPropertiesToCjsFile.apply(this, arguments);
}
/* Write Custom Properties to Module JS file
/* ========================================================================== */
function _writeCustomPropertiesToCjsFile() {
_writeCustomPropertiesToCjsFile = _asyncToGenerator(function* (to, customProperties) {
const jsContents = Object.keys(customProperties).reduce((jsLines, name) => {
jsLines.push(`\t\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`);
return jsLines;
}, []).join(',\n');
const js = `module.exports = {\n\tcustomProperties: {\n${jsContents}\n\t}\n};\n`;
yield writeFile(to, js);
});
return _writeCustomPropertiesToCjsFile.apply(this, arguments);
}
function writeCustomPropertiesToMjsFile(_x7, _x8) {
return _writeCustomPropertiesToMjsFile.apply(this, arguments);
}
/* Write Custom Properties to Exports
/* ========================================================================== */
function _writeCustomPropertiesToMjsFile() {
_writeCustomPropertiesToMjsFile = _asyncToGenerator(function* (to, customProperties) {
const mjsContents = Object.keys(customProperties).reduce((mjsLines, name) => {
mjsLines.push(`\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`);
return mjsLines;
}, []).join(',\n');
const mjs = `export const customProperties = {\n${mjsContents}\n};\n`;
yield writeFile(to, mjs);
});
return _writeCustomPropertiesToMjsFile.apply(this, arguments);
}
function writeCustomPropertiesToExports(customProperties, destinations) {
return Promise.all(destinations.map(
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (destination) {
if (destination instanceof Function) {
yield destination(defaultCustomPropertiesToJSON(customProperties));
} else {
// read the destination as an object
const opts = destination === Object(destination) ? destination : {
to: String(destination)
}; // transformer for Custom Properties into a JSON-compatible object
const toJSON = opts.toJSON || defaultCustomPropertiesToJSON;
if ('customProperties' in opts) {
// write directly to an object as customProperties
opts.customProperties = toJSON(customProperties);
} else if ('custom-properties' in opts) {
// write directly to an object as custom-properties
opts['custom-properties'] = toJSON(customProperties);
} else {
// destination pathname
const to = String(opts.to || ''); // type of file being written to
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); // transformed Custom Properties
const customPropertiesJSON = toJSON(customProperties);
if (type === 'css') {
yield writeCustomPropertiesToCssFile(to, customPropertiesJSON);
}
if (type === 'js') {
yield writeCustomPropertiesToCjsFile(to, customPropertiesJSON);
}
if (type === 'json') {
yield writeCustomPropertiesToJsonFile(to, customPropertiesJSON);
}
if (type === 'mjs') {
yield writeCustomPropertiesToMjsFile(to, customPropertiesJSON);
}
}
}
});
return function (_x9) {
return _ref.apply(this, arguments);
};
}()));
}
/* Helper utilities
/* ========================================================================== */
const defaultCustomPropertiesToJSON = customProperties => {
return Object.keys(customProperties).reduce((customPropertiesJSON, key) => {
customPropertiesJSON[key] = String(customProperties[key]);
return customPropertiesJSON;
}, {});
};
const writeFile = (to, text) => new Promise((resolve, reject) => {
fs.writeFile(to, text, error => {
if (error) {
reject(error);
} else {
resolve();
}
});
});
const escapeForJS = string => string.replace(/\\([\s\S])|(')/g, '\\$1$2').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
var index = postcss.plugin('postcss-custom-properties', opts => {
// whether to preserve custom selectors and rules using them
const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : true; // sources to import custom selectors from
const importFrom = [].concat(Object(opts).importFrom || []); // destinations to export custom selectors to
const exportTo = [].concat(Object(opts).exportTo || []); // promise any custom selectors are imported
const customPropertiesPromise = getCustomPropertiesFromImports(importFrom); // synchronous transform
const syncTransform = root => {
const customProperties = getCustomPropertiesFromRoot(root, {
preserve
});
transformProperties(root, customProperties, {
preserve
});
}; // asynchronous transform
const asyncTransform =
/*#__PURE__*/
function () {
var _ref = _asyncToGenerator(function* (root) {
const customProperties = Object.assign({}, (yield customPropertiesPromise), getCustomPropertiesFromRoot(root, {
preserve
}));
yield writeCustomPropertiesToExports(customProperties, exportTo);
transformProperties(root, customProperties, {
preserve
});
});
return function asyncTransform(_x) {
return _ref.apply(this, arguments);
};
}(); // whether to return synchronous function if no asynchronous operations are requested
const canReturnSyncFunction = importFrom.length === 0 && exportTo.length === 0;
return canReturnSyncFunction ? syncTransform : asyncTransform;
});
export default index;
//# sourceMappingURL=index.esm.mjs.map

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,74 @@
{
"name": "postcss-custom-properties",
"version": "8.0.11",
"description": "Use Custom Properties Queries in CSS",
"author": "Jonathan Neal <jonathantneal@hotmail.com>",
"contributors": [
"Maxime Thirouin"
],
"license": "MIT",
"repository": "postcss/postcss-custom-properties",
"homepage": "https://github.com/postcss/postcss-custom-properties#readme",
"bugs": "https://github.com/postcss/postcss-custom-properties/issues",
"main": "index.cjs.js",
"module": "index.esm.mjs",
"files": [
"index.cjs.js",
"index.cjs.js.map",
"index.esm.mjs",
"index.esm.mjs.map"
],
"scripts": {
"prepublishOnly": "npm test",
"pretest:tape": "rollup -c .rollup.js --silent",
"test": "npm run test:js && npm run test:tape",
"test:js": "eslint src/{*,**/*}.js --cache --ignore-path .gitignore --quiet",
"test:tape": "postcss-tape"
},
"engines": {
"node": ">=6.0.0"
},
"dependencies": {
"postcss": "^7.0.17",
"postcss-values-parser": "^2.0.1"
},
"devDependencies": {
"@babel/core": "^7.4.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.4.5",
"babel-eslint": "^10.0.2",
"eslint": "^5.16.0",
"postcss-tape": "^4.0.0",
"pre-commit": "^1.2.2",
"rollup": "^1.15.6",
"rollup-plugin-babel": "^4.3.2"
},
"eslintConfig": {
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"impliedStrict": true,
"sourceType": "module"
},
"root": true
},
"keywords": [
"postcss",
"css",
"postcss-plugin",
"custom",
"properties",
"declarations",
"variables",
"vars",
"w3c",
"csswg",
"specification"
]
}