This commit is contained in:
2023-08-11 10:45:20 +08:00
commit 161ca982f3
31850 changed files with 2706500 additions and 0 deletions

11
node_modules/postcss-pxtorem/.editorconfig generated vendored Normal file
View File

@ -0,0 +1,11 @@
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

18
node_modules/postcss-pxtorem/.eslintrc.js generated vendored Normal file
View File

@ -0,0 +1,18 @@
module.exports = {
env: {
commonjs: true,
es6: true,
node: true
},
extends: "eslint:recommended",
globals: {
Atomics: "readonly",
SharedArrayBuffer: "readonly"
},
parserOptions: {
ecmaVersion: 2018
},
rules: {
"no-console": 1
}
};

1
node_modules/postcss-pxtorem/.gitattributes generated vendored Normal file
View File

@ -0,0 +1 @@
* text=auto eol=lf

4
node_modules/postcss-pxtorem/.prettierrc generated vendored Normal file
View File

@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}

9
node_modules/postcss-pxtorem/LICENSE generated vendored Normal file
View File

@ -0,0 +1,9 @@
(MIT License)
Copyright (C) 2014 Jonathan Cuthbert <jon@cuth.net>
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.

139
node_modules/postcss-pxtorem/README.md generated vendored Normal file
View File

@ -0,0 +1,139 @@
# postcss-pxtorem [![NPM version](https://badge.fury.io/js/postcss-pxtorem.svg)](http://badge.fury.io/js/postcss-pxtorem)
A plugin for [PostCSS](https://github.com/ai/postcss) that generates rem units from pixel units.
## Install
```shell
$ npm install postcss postcss-pxtorem --save-dev
```
## Usage
Pixels are the easiest unit to use (*opinion*). The only issue with them is that they don't let browsers change the default font size of 16. This script converts every px value to a rem from the properties you choose to allow the browser to set the font size.
### Input/Output
*With the default settings, only font related properties are targeted.*
```css
// input
h1 {
margin: 0 0 20px;
font-size: 32px;
line-height: 1.2;
letter-spacing: 1px;
}
// output
h1 {
margin: 0 0 20px;
font-size: 2rem;
line-height: 1.2;
letter-spacing: 0.0625rem;
}
```
### Example
```js
var fs = require('fs');
var postcss = require('postcss');
var pxtorem = require('postcss-pxtorem');
var css = fs.readFileSync('main.css', 'utf8');
var options = {
replace: false
};
var processedCss = postcss(pxtorem(options)).process(css).css;
fs.writeFile('main-rem.css', processedCss, function (err) {
if (err) {
throw err;
}
console.log('Rem file written.');
});
```
### options
Type: `Object | Null`
Default:
```js
{
rootValue: 16,
unitPrecision: 5,
propList: ['font', 'font-size', 'line-height', 'letter-spacing'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minPixelValue: 0,
exclude: /node_modules/i
}
```
- `rootValue` (Number | Function) Represents the root element font size or returns the root element font size based on the [`input`](https://api.postcss.org/Input.html) parameter
- `unitPrecision` (Number) The decimal numbers to allow the REM units to grow to.
- `propList` (Array) The properties that can change from px to rem.
- Values need to be exact matches.
- Use wildcard `*` to enable all properties. Example: `['*']`
- Use `*` at the start or end of a word. (`['*position*']` will match `background-position-y`)
- Use `!` to not match a property. Example: `['*', '!letter-spacing']`
- Combine the "not" prefix with the other prefixes. Example: `['*', '!font*']`
- `selectorBlackList` (Array) The selectors to ignore and leave as px.
- If value is string, it checks to see if selector contains the string.
- `['body']` will match `.body-class`
- If value is regexp, it checks to see if the selector matches the regexp.
- `[/^body$/]` will match `body` but not `.body`
- `replace` (Boolean) Replaces rules containing rems instead of adding fallbacks.
- `mediaQuery` (Boolean) Allow px to be converted in media queries.
- `minPixelValue` (Number) Set the minimum pixel value to replace.
- `exclude` (String, Regexp, Function) The file path to ignore and leave as px.
- If value is string, it checks to see if file path contains the string.
- `'exclude'` will match `\project\postcss-pxtorem\exclude\path`
- If value is regexp, it checks to see if file path matches the regexp.
- `/exclude/i` will match `\project\postcss-pxtorem\exclude\path`
- If value is function, you can use exclude function to return a true and the file will be ignored.
- the callback will pass the file path as a parameter, it should returns a Boolean result.
- `function (file) { return file.indexOf('exclude') !== -1; }`
### Use with gulp-postcss and autoprefixer
```js
var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var pxtorem = require('postcss-pxtorem');
gulp.task('css', function () {
var processors = [
autoprefixer({
browsers: 'last 1 version'
}),
pxtorem({
replace: false
})
];
return gulp.src(['build/css/**/*.css'])
.pipe(postcss(processors))
.pipe(gulp.dest('build/css'));
});
```
### A message about ignoring properties
Currently, the easiest way to have a single property ignored is to use a capital in the pixel unit declaration.
```css
// `px` is converted to `rem`
.convert {
font-size: 16px; // converted to 1rem
}
// `Px` or `PX` is ignored by `postcss-pxtorem` but still accepted by browsers
.ignore {
border: 1Px solid; // ignored
border-width: 2PX; // ignored
}
```

182
node_modules/postcss-pxtorem/index.js generated vendored Normal file
View File

@ -0,0 +1,182 @@
const pxRegex = require("./lib/pixel-unit-regex");
const filterPropList = require("./lib/filter-prop-list");
const type = require("./lib/type");
const defaults = {
rootValue: 16,
unitPrecision: 5,
selectorBlackList: [],
propList: ["font", "font-size", "line-height", "letter-spacing"],
replace: true,
mediaQuery: false,
minPixelValue: 0,
exclude: null
};
const legacyOptions = {
root_value: "rootValue",
unit_precision: "unitPrecision",
selector_black_list: "selectorBlackList",
prop_white_list: "propList",
media_query: "mediaQuery",
propWhiteList: "propList"
};
function convertLegacyOptions(options) {
if (typeof options !== "object") return;
if (
((typeof options["prop_white_list"] !== "undefined" &&
options["prop_white_list"].length === 0) ||
(typeof options.propWhiteList !== "undefined" &&
options.propWhiteList.length === 0)) &&
typeof options.propList === "undefined"
) {
options.propList = ["*"];
delete options["prop_white_list"];
delete options.propWhiteList;
}
Object.keys(legacyOptions).forEach(key => {
if (Reflect.has(options, key)) {
options[legacyOptions[key]] = options[key];
delete options[key];
}
});
}
function createPxReplace(rootValue, unitPrecision, minPixelValue) {
return (m, $1) => {
if (!$1) return m;
const pixels = parseFloat($1);
if (pixels < minPixelValue) return m;
const fixedVal = toFixed(pixels / rootValue, unitPrecision);
return fixedVal === 0 ? "0" : fixedVal + "rem";
};
}
function toFixed(number, precision) {
const multiplier = Math.pow(10, precision + 1),
wholeNumber = Math.floor(number * multiplier);
return (Math.round(wholeNumber / 10) * 10) / multiplier;
}
function declarationExists(decls, prop, value) {
return decls.some(decl => decl.prop === prop && decl.value === value);
}
function blacklistedSelector(blacklist, selector) {
if (typeof selector !== "string") return;
return blacklist.some(regex => {
if (typeof regex === "string") {
return selector.indexOf(regex) !== -1;
}
return selector.match(regex);
});
}
function createPropListMatcher(propList) {
const hasWild = propList.indexOf("*") > -1;
const matchAll = hasWild && propList.length === 1;
const lists = {
exact: filterPropList.exact(propList),
contain: filterPropList.contain(propList),
startWith: filterPropList.startWith(propList),
endWith: filterPropList.endWith(propList),
notExact: filterPropList.notExact(propList),
notContain: filterPropList.notContain(propList),
notStartWith: filterPropList.notStartWith(propList),
notEndWith: filterPropList.notEndWith(propList)
};
return prop => {
if (matchAll) return true;
return (
(hasWild ||
lists.exact.indexOf(prop) > -1 ||
lists.contain.some(function(m) {
return prop.indexOf(m) > -1;
}) ||
lists.startWith.some(function(m) {
return prop.indexOf(m) === 0;
}) ||
lists.endWith.some(function(m) {
return prop.indexOf(m) === prop.length - m.length;
})) &&
!(
lists.notExact.indexOf(prop) > -1 ||
lists.notContain.some(function(m) {
return prop.indexOf(m) > -1;
}) ||
lists.notStartWith.some(function(m) {
return prop.indexOf(m) === 0;
}) ||
lists.notEndWith.some(function(m) {
return prop.indexOf(m) === prop.length - m.length;
})
)
);
};
}
module.exports = (options = {}) => {
convertLegacyOptions(options);
const opts = Object.assign({}, defaults, options);
const satisfyPropList = createPropListMatcher(opts.propList);
const exclude = opts.exclude;
let isExcludeFile = false;
let pxReplace;
return {
postcssPlugin: "postcss-pxtorem",
Once(css) {
const filePath = css.source.input.file;
if (
exclude &&
((type.isFunction(exclude) && exclude(filePath)) ||
(type.isString(exclude) && filePath.indexOf(exclude) !== -1) ||
filePath.match(exclude) !== null)
) {
isExcludeFile = true;
} else {
isExcludeFile = false;
}
const rootValue =
typeof opts.rootValue === "function"
? opts.rootValue(css.source.input)
: opts.rootValue;
pxReplace = createPxReplace(
rootValue,
opts.unitPrecision,
opts.minPixelValue
);
},
Declaration(decl) {
if (isExcludeFile) return;
if (
decl.value.indexOf("px") === -1 ||
!satisfyPropList(decl.prop) ||
blacklistedSelector(opts.selectorBlackList, decl.parent.selector)
)
return;
const value = decl.value.replace(pxRegex, pxReplace);
// if rem unit already exists, do not add or replace
if (declarationExists(decl.parent, decl.prop, value)) return;
if (opts.replace) {
decl.value = value;
} else {
decl.cloneAfter({ value: value });
}
},
AtRule(atRule) {
if (isExcludeFile) return;
if (opts.mediaQuery && atRule.name === "media") {
if (atRule.params.indexOf("px") === -1) return;
atRule.params = atRule.params.replace(pxRegex, pxReplace);
}
}
};
};
module.exports.postcss = true;

16
node_modules/postcss-pxtorem/lib/filter-prop-list.js generated vendored Normal file
View File

@ -0,0 +1,16 @@
module.exports = {
exact: list => list.filter(m => m.match(/^[^*!]+$/)),
contain: list =>
list.filter(m => m.match(/^\*.+\*$/)).map(m => m.substr(1, m.length - 2)),
endWith: list => list.filter(m => m.match(/^\*[^*]+$/)).map(m => m.substr(1)),
startWith: list =>
list.filter(m => m.match(/^[^*!]+\*$/)).map(m => m.substr(0, m.length - 1)),
notExact: list =>
list.filter(m => m.match(/^![^*].*$/)).map(m => m.substr(1)),
notContain: list =>
list.filter(m => m.match(/^!\*.+\*$/)).map(m => m.substr(2, m.length - 3)),
notEndWith: list =>
list.filter(m => m.match(/^!\*[^*]+$/)).map(m => m.substr(2)),
notStartWith: list =>
list.filter(m => m.match(/^![^*]+\*$/)).map(m => m.substr(1, m.length - 2))
};

9
node_modules/postcss-pxtorem/lib/pixel-unit-regex.js generated vendored Normal file
View File

@ -0,0 +1,9 @@
// excluding regex trick: http://www.rexegg.com/regex-best-trick.html
// Not anything inside double quotes
// Not anything inside single quotes
// Not anything inside url()
// Any digit followed by px
// !singlequotes|!doublequotes|!url()|pixelunit
module.exports = /"[^"]+"|'[^']+'|url\([^)]+\)|var\([^)]+\)|(\d*\.?\d+)px/g;

21
node_modules/postcss-pxtorem/lib/type.js generated vendored Normal file
View File

@ -0,0 +1,21 @@
const type = s =>
Object.prototype.toString
.call(s)
.slice(8, -1)
.toLowerCase();
const types = [
"String",
"Array",
"Undefined",
"Boolean",
"Number",
"Function",
"Symbol",
"Object"
];
module.exports = types.reduce((acc, str) => {
acc["is" + str] = val => type(val) === str.toLowerCase();
return acc;
}, {});

77
node_modules/postcss-pxtorem/package.json generated vendored Normal file
View File

@ -0,0 +1,77 @@
{
"_from": "postcss-pxtorem@6.0.0",
"_id": "postcss-pxtorem@6.0.0",
"_inBundle": false,
"_integrity": "sha512-ZRXrD7MLLjLk2RNGV6UA4f5Y7gy+a/j1EqjAfp9NdcNYVjUMvg5HTYduTjSkKBkRkfqbg/iKrjMO70V4g1LZeg==",
"_location": "/postcss-pxtorem",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "postcss-pxtorem@6.0.0",
"name": "postcss-pxtorem",
"escapedName": "postcss-pxtorem",
"rawSpec": "6.0.0",
"saveSpec": null,
"fetchSpec": "6.0.0"
},
"_requiredBy": [
"#DEV:/"
],
"_resolved": "https://registry.npmjs.org/postcss-pxtorem/-/postcss-pxtorem-6.0.0.tgz",
"_shasum": "f228a4d05d8a73f0642eabae950e2b19836366d7",
"_spec": "postcss-pxtorem@6.0.0",
"_where": "C:\\Users\\zhouxueli\\Desktop\\scheduling-app",
"author": {
"name": "cuth"
},
"bugs": {
"url": "https://github.com/cuth/postcss-pxtorem/issues"
},
"bundleDependencies": false,
"deprecated": false,
"description": "A CSS post-processor that converts px to rem.",
"devDependencies": {
"eslint": "^6.8.0",
"husky": "^4.2.3",
"jasmine-node": "^3.0.0",
"lint-staged": "^10.0.8",
"postcss": "^8.0.0",
"prettier": "^1.19.1"
},
"homepage": "https://github.com/cuth/postcss-pxtorem#readme",
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"keywords": [
"css",
"rem",
"pixel",
"px",
"postcss",
"postcss-plugin"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"eslint --fix",
"prettier --write"
]
},
"main": "index.js",
"name": "postcss-pxtorem",
"peerDependencies": {
"postcss": "^8.0.0"
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/cuth/postcss-pxtorem.git"
},
"scripts": {
"lint": "eslint .",
"test": "jasmine-node spec"
},
"version": "6.0.0"
}

543
node_modules/postcss-pxtorem/spec/pxtorem-spec.js generated vendored Normal file
View File

@ -0,0 +1,543 @@
// Jasmine unit tests
// To run tests, run these commands from the project root:
// 1. `npm install -g jasmine-node`
// 2. `jasmine-node spec`
/* global describe, it, expect */
"use strict";
var postcss = require("postcss");
var pxtorem = require("..");
var basicCSS = ".rule { font-size: 15px }";
var filterPropList = require("../lib/filter-prop-list");
describe("pxtorem", function() {
it("should work on the readme example", function() {
var input =
"h1 { margin: 0 0 20px; font-size: 32px; line-height: 1.2; letter-spacing: 1px; }";
var output =
"h1 { margin: 0 0 20px; font-size: 2rem; line-height: 1.2; letter-spacing: 0.0625rem; }";
var processed = postcss(pxtorem()).process(input).css;
expect(processed).toBe(output);
});
it("should replace the px unit with rem", function() {
var processed = postcss(pxtorem()).process(basicCSS).css;
var expected = ".rule { font-size: 0.9375rem }";
expect(processed).toBe(expected);
});
it("should ignore non px properties", function() {
var expected = ".rule { font-size: 2em }";
var processed = postcss(pxtorem()).process(expected).css;
expect(processed).toBe(expected);
});
it("should handle < 1 values and values without a leading 0 - legacy", function() {
var rules = ".rule { margin: 0.5rem .5px -0.2px -.2em }";
var expected = ".rule { margin: 0.5rem 0.03125rem -0.0125rem -.2em }";
var options = {
propWhiteList: ["margin"]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should ignore px in custom property names", function() {
var rules =
":root { --rem-14px: 14px; } .rule { font-size: var(--rem-14px); }";
var expected =
":root { --rem-14px: 0.875rem; } .rule { font-size: var(--rem-14px); }";
var options = {
propList: ["--*", "font-size"]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should handle < 1 values and values without a leading 0", function() {
var rules = ".rule { margin: 0.5rem .5px -0.2px -.2em }";
var expected = ".rule { margin: 0.5rem 0.03125rem -0.0125rem -.2em }";
var options = {
propList: ["margin"]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should not add properties that already exist", function() {
var expected = ".rule { font-size: 16px; font-size: 1rem; }";
var processed = postcss(pxtorem()).process(expected).css;
expect(processed).toBe(expected);
});
it("should remain unitless if 0", function() {
var expected = ".rule { font-size: 0px; font-size: 0; }";
var processed = postcss(pxtorem()).process(expected).css;
expect(processed).toBe(expected);
});
});
describe("value parsing", function() {
it("should not replace values in double quotes or single quotes - legacy", function() {
var options = {
propWhiteList: []
};
var rules =
".rule { content: '16px'; font-family: \"16px\"; font-size: 16px; }";
var expected =
".rule { content: '16px'; font-family: \"16px\"; font-size: 1rem; }";
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should not replace values in double quotes or single quotes", function() {
var options = {
propList: ["*"]
};
var rules =
".rule { content: '16px'; font-family: \"16px\"; font-size: 16px; }";
var expected =
".rule { content: '16px'; font-family: \"16px\"; font-size: 1rem; }";
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should not replace values in `url()` - legacy", function() {
var options = {
propWhiteList: []
};
var rules = ".rule { background: url(16px.jpg); font-size: 16px; }";
var expected = ".rule { background: url(16px.jpg); font-size: 1rem; }";
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should not replace values in `url()`", function() {
var options = {
propList: ["*"]
};
var rules = ".rule { background: url(16px.jpg); font-size: 16px; }";
var expected = ".rule { background: url(16px.jpg); font-size: 1rem; }";
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should not replace values with an uppercase P or X", function() {
var options = {
propList: ["*"]
};
var rules =
".rule { margin: 12px calc(100% - 14PX); height: calc(100% - 20px); font-size: 12Px; line-height: 16px; }";
var expected =
".rule { margin: 0.75rem calc(100% - 14PX); height: calc(100% - 1.25rem); font-size: 12Px; line-height: 1rem; }";
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
});
describe("rootValue", function() {
// Deprecate
it("should replace using a root value of 10 - legacy", function() {
var expected = ".rule { font-size: 1.5rem }";
var options = {
root_value: 10
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
expect(processed).toBe(expected);
});
it("should replace using a root value of 10", function() {
var expected = ".rule { font-size: 1.5rem }";
var options = {
rootValue: 10
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
expect(processed).toBe(expected);
});
it("should replace using different root values with different files", function() {
var css2 = ".rule { font-size: 20px }";
var expected = ".rule { font-size: 1rem }";
var options = {
rootValue: function(input) {
if (input.from.indexOf("basic.css") !== -1) {
return 15;
}
return 20;
}
};
var processed1 = postcss(pxtorem(options)).process(basicCSS, {
from: "/tmp/basic.css"
}).css;
var processed2 = postcss(pxtorem(options)).process(css2, {
from: "/tmp/whatever.css"
}).css;
expect(processed1).toBe(expected);
expect(processed2).toBe(expected);
});
});
describe("unitPrecision", function() {
// Deprecate
it("should replace using a decimal of 2 places - legacy", function() {
var expected = ".rule { font-size: 0.94rem }";
var options = {
unit_precision: 2
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
expect(processed).toBe(expected);
});
it("should replace using a decimal of 2 places", function() {
var expected = ".rule { font-size: 0.94rem }";
var options = {
unitPrecision: 2
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
expect(processed).toBe(expected);
});
});
describe("propWhiteList", function() {
// Deprecate
it("should only replace properties in the white list - legacy", function() {
var expected = ".rule { font-size: 15px }";
var options = {
prop_white_list: ["font"]
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
expect(processed).toBe(expected);
});
it("should only replace properties in the white list - legacy", function() {
var expected = ".rule { font-size: 15px }";
var options = {
propWhiteList: ["font"]
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
expect(processed).toBe(expected);
});
it("should only replace properties in the white list - legacy", function() {
var css = ".rule { margin: 16px; margin-left: 10px }";
var expected = ".rule { margin: 1rem; margin-left: 10px }";
var options = {
propWhiteList: ["margin"]
};
var processed = postcss(pxtorem(options)).process(css).css;
expect(processed).toBe(expected);
});
it("should only replace properties in the prop list", function() {
var css =
".rule { font-size: 16px; margin: 16px; margin-left: 5px; padding: 5px; padding-right: 16px }";
var expected =
".rule { font-size: 1rem; margin: 1rem; margin-left: 5px; padding: 5px; padding-right: 1rem }";
var options = {
propWhiteList: ["*font*", "margin*", "!margin-left", "*-right", "pad"]
};
var processed = postcss(pxtorem(options)).process(css).css;
expect(processed).toBe(expected);
});
it("should only replace properties in the prop list with wildcard", function() {
var css =
".rule { font-size: 16px; margin: 16px; margin-left: 5px; padding: 5px; padding-right: 16px }";
var expected =
".rule { font-size: 16px; margin: 1rem; margin-left: 5px; padding: 5px; padding-right: 16px }";
var options = {
propWhiteList: ["*", "!margin-left", "!*padding*", "!font*"]
};
var processed = postcss(pxtorem(options)).process(css).css;
expect(processed).toBe(expected);
});
it("should replace all properties when white list is empty", function() {
var rules = ".rule { margin: 16px; font-size: 15px }";
var expected = ".rule { margin: 1rem; font-size: 0.9375rem }";
var options = {
propWhiteList: []
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
});
describe("selectorBlackList", function() {
// Deprecate
it("should ignore selectors in the selector black list - legacy", function() {
var rules = ".rule { font-size: 15px } .rule2 { font-size: 15px }";
var expected = ".rule { font-size: 0.9375rem } .rule2 { font-size: 15px }";
var options = {
selector_black_list: [".rule2"]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should ignore selectors in the selector black list", function() {
var rules = ".rule { font-size: 15px } .rule2 { font-size: 15px }";
var expected = ".rule { font-size: 0.9375rem } .rule2 { font-size: 15px }";
var options = {
selectorBlackList: [".rule2"]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should ignore every selector with `body$`", function() {
var rules =
"body { font-size: 16px; } .class-body$ { font-size: 16px; } .simple-class { font-size: 16px; }";
var expected =
"body { font-size: 1rem; } .class-body$ { font-size: 16px; } .simple-class { font-size: 1rem; }";
var options = {
selectorBlackList: ["body$"]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
it("should only ignore exactly `body`", function() {
var rules =
"body { font-size: 16px; } .class-body { font-size: 16px; } .simple-class { font-size: 16px; }";
var expected =
"body { font-size: 16px; } .class-body { font-size: 1rem; } .simple-class { font-size: 1rem; }";
var options = {
selectorBlackList: [/^body$/]
};
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
});
describe("replace", function() {
it("should leave fallback pixel unit with root em value", function() {
var options = {
replace: false
};
var processed = postcss(pxtorem(options)).process(basicCSS).css;
var expected = ".rule { font-size: 15px; font-size: 0.9375rem }";
expect(processed).toBe(expected);
});
});
describe("mediaQuery", function() {
// Deprecate
it("should replace px in media queries", function() {
var options = {
media_query: true
};
var processed = postcss(pxtorem(options)).process(
"@media (min-width: 500px) { .rule { font-size: 16px } }"
).css;
var expected = "@media (min-width: 31.25rem) { .rule { font-size: 1rem } }";
expect(processed).toBe(expected);
});
it("should replace px in media queries", function() {
var options = {
mediaQuery: true
};
var processed = postcss(pxtorem(options)).process(
"@media (min-width: 500px) { .rule { font-size: 16px } }"
).css;
var expected = "@media (min-width: 31.25rem) { .rule { font-size: 1rem } }";
expect(processed).toBe(expected);
});
});
describe("minPixelValue", function() {
it("should not replace values below minPixelValue", function() {
var options = {
propWhiteList: [],
minPixelValue: 2
};
var rules =
".rule { border: 1px solid #000; font-size: 16px; margin: 1px 10px; }";
var expected =
".rule { border: 1px solid #000; font-size: 1rem; margin: 1px 0.625rem; }";
var processed = postcss(pxtorem(options)).process(rules).css;
expect(processed).toBe(expected);
});
});
describe("filter-prop-list", function() {
it('should find "exact" matches from propList', function() {
var propList = [
"font-size",
"margin",
"!padding",
"*border*",
"*",
"*y",
"!*font*"
];
var expected = "font-size,margin";
expect(filterPropList.exact(propList).join()).toBe(expected);
});
it('should find "contain" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"*border*",
"*",
"*y",
"!*font*"
];
var expected = "margin,border";
expect(filterPropList.contain(propList).join()).toBe(expected);
});
it('should find "start" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"border*",
"*",
"*y",
"!*font*"
];
var expected = "border";
expect(filterPropList.startWith(propList).join()).toBe(expected);
});
it('should find "end" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"border*",
"*",
"*y",
"!*font*"
];
var expected = "y";
expect(filterPropList.endWith(propList).join()).toBe(expected);
});
it('should find "not" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"border*",
"*",
"*y",
"!*font*"
];
var expected = "padding";
expect(filterPropList.notExact(propList).join()).toBe(expected);
});
it('should find "not contain" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"!border*",
"*",
"*y",
"!*font*"
];
var expected = "font";
expect(filterPropList.notContain(propList).join()).toBe(expected);
});
it('should find "not start" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"!border*",
"*",
"*y",
"!*font*"
];
var expected = "border";
expect(filterPropList.notStartWith(propList).join()).toBe(expected);
});
it('should find "not end" matches from propList and reduce to string', function() {
var propList = [
"font-size",
"*margin*",
"!padding",
"!border*",
"*",
"!*y",
"!*font*"
];
var expected = "y";
expect(filterPropList.notEndWith(propList).join()).toBe(expected);
});
});
describe("exclude", function() {
it("should ignore file path with exclude RegEx", function() {
var options = {
exclude: /exclude/i
};
var processed = postcss(pxtorem(options)).process(basicCSS, {
from: "exclude/path"
}).css;
expect(processed).toBe(basicCSS);
});
it("should not ignore file path with exclude String", function() {
var options = {
exclude: "exclude"
};
var processed = postcss(pxtorem(options)).process(basicCSS, {
from: "exclude/path"
}).css;
expect(processed).toBe(basicCSS);
});
it("should not ignore file path with exclude function", function() {
var options = {
exclude: function(file) {
return file.indexOf("exclude") !== -1;
}
};
var processed = postcss(pxtorem(options)).process(basicCSS, {
from: "exclude/path"
}).css;
expect(processed).toBe(basicCSS);
});
});