postcss-normalize-unicode 5.0.0 → 5.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -14
- package/src/index.js +117 -0
- package/CHANGELOG.md +0 -56
- package/dist/index.js +0 -114
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-unicode",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.4",
|
|
4
4
|
"description": "Normalize unicode-range descriptors, and can convert to wildcard ranges.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
7
|
+
"src",
|
|
8
8
|
"LICENSE-MIT"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "yarn build"
|
|
14
|
-
},
|
|
15
10
|
"keywords": [
|
|
16
11
|
"css",
|
|
17
12
|
"postcss",
|
|
@@ -26,8 +21,8 @@
|
|
|
26
21
|
},
|
|
27
22
|
"repository": "cssnano/cssnano",
|
|
28
23
|
"dependencies": {
|
|
29
|
-
"browserslist": "^4.16.
|
|
30
|
-
"postcss-value-parser": "^4.
|
|
24
|
+
"browserslist": "^4.16.6",
|
|
25
|
+
"postcss-value-parser": "^4.2.0"
|
|
31
26
|
},
|
|
32
27
|
"bugs": {
|
|
33
28
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -36,10 +31,10 @@
|
|
|
36
31
|
"node": "^10 || ^12 || >=14.0"
|
|
37
32
|
},
|
|
38
33
|
"devDependencies": {
|
|
39
|
-
"postcss": "^8.2.
|
|
34
|
+
"postcss": "^8.2.15"
|
|
40
35
|
},
|
|
41
36
|
"peerDependencies": {
|
|
42
|
-
"postcss": "^8.2.
|
|
37
|
+
"postcss": "^8.2.15"
|
|
43
38
|
},
|
|
44
|
-
"
|
|
45
|
-
}
|
|
39
|
+
"readme": "# [postcss][postcss]-normalize-unicode\n\n> Normalize unicode with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-normalize-unicode) do:\n\n```\nnpm install postcss-normalize-unicode --save\n```\n\n## Example\n\n### Input\n\n```css\n@font-face{\n font-family: test;\n unicode-range: u+2b00-2bff\n}\n```\n\n### Output\n\n```css\n@font-face{\n font-family: test;\n unicode-range: u+2b??\n}\n``` \n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
40
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const browserslist = require('browserslist');
|
|
3
|
+
const valueParser = require('postcss-value-parser');
|
|
4
|
+
|
|
5
|
+
const regexLowerCaseUPrefix = /^u(?=\+)/;
|
|
6
|
+
|
|
7
|
+
function unicode(range) {
|
|
8
|
+
const values = range.slice(2).split('-');
|
|
9
|
+
|
|
10
|
+
if (values.length < 2) {
|
|
11
|
+
return range;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const left = values[0].split('');
|
|
15
|
+
const right = values[1].split('');
|
|
16
|
+
|
|
17
|
+
if (left.length !== right.length) {
|
|
18
|
+
return range;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const merged = mergeRangeBounds(left, right);
|
|
22
|
+
|
|
23
|
+
if (merged) {
|
|
24
|
+
return merged;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return range;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param {string[]} left
|
|
31
|
+
* @param {string[]} right
|
|
32
|
+
* @return {false|string}
|
|
33
|
+
*/
|
|
34
|
+
function mergeRangeBounds(left, right) {
|
|
35
|
+
let questionCounter = 0;
|
|
36
|
+
let group = 'u+';
|
|
37
|
+
for (const [index, value] of left.entries()) {
|
|
38
|
+
if (value === right[index] && questionCounter === 0) {
|
|
39
|
+
group = group + value;
|
|
40
|
+
} else if (value === '0' && right[index] === 'f') {
|
|
41
|
+
questionCounter++;
|
|
42
|
+
group = group + '?';
|
|
43
|
+
} else {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// The maximum number of wildcard characters (?) for ranges is 5.
|
|
48
|
+
if (questionCounter < 6) {
|
|
49
|
+
return group;
|
|
50
|
+
} else {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/*
|
|
56
|
+
* IE and Edge before 16 version ignore the unicode-range if the 'U' is lowercase
|
|
57
|
+
*
|
|
58
|
+
* https://caniuse.com/#search=unicode-range
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
function hasLowerCaseUPrefixBug(browser) {
|
|
62
|
+
return browserslist('ie <=11, edge <= 15').includes(browser);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function transform(value, isLegacy = false) {
|
|
66
|
+
return valueParser(value)
|
|
67
|
+
.walk((child) => {
|
|
68
|
+
if (child.type === 'unicode-range') {
|
|
69
|
+
const transformed = unicode(child.value.toLowerCase());
|
|
70
|
+
|
|
71
|
+
child.value = isLegacy
|
|
72
|
+
? transformed.replace(regexLowerCaseUPrefix, 'U')
|
|
73
|
+
: transformed;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return false;
|
|
77
|
+
})
|
|
78
|
+
.toString();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function pluginCreator() {
|
|
82
|
+
return {
|
|
83
|
+
postcssPlugin: 'postcss-normalize-unicode',
|
|
84
|
+
prepare(result) {
|
|
85
|
+
const cache = new Map();
|
|
86
|
+
const resultOpts = result.opts || {};
|
|
87
|
+
const browsers = browserslist(null, {
|
|
88
|
+
stats: resultOpts.stats,
|
|
89
|
+
path: __dirname,
|
|
90
|
+
env: resultOpts.env,
|
|
91
|
+
});
|
|
92
|
+
const isLegacy = browsers.some(hasLowerCaseUPrefixBug);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
OnceExit(css) {
|
|
96
|
+
css.walkDecls(/^unicode-range$/i, (decl) => {
|
|
97
|
+
const value = decl.value;
|
|
98
|
+
|
|
99
|
+
if (cache.has(value)) {
|
|
100
|
+
decl.value = cache.get(value);
|
|
101
|
+
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const newValue = transform(value, isLegacy);
|
|
106
|
+
|
|
107
|
+
decl.value = newValue;
|
|
108
|
+
cache.set(value, newValue);
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
pluginCreator.postcss = true;
|
|
117
|
+
module.exports = pluginCreator;
|
package/CHANGELOG.md
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-normalize-unicode@5.0.0-rc.2...postcss-normalize-unicode@5.0.0) (2021-04-06)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package postcss-normalize-unicode
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-normalize-unicode@5.0.0-rc.1...postcss-normalize-unicode@5.0.0-rc.2) (2021-03-15)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package postcss-normalize-unicode
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-normalize-unicode@5.0.0-rc.0...postcss-normalize-unicode@5.0.0-rc.1) (2021-03-04)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package postcss-normalize-unicode
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### chore
|
|
34
|
-
|
|
35
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Features
|
|
39
|
-
|
|
40
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### BREAKING CHANGES
|
|
44
|
-
|
|
45
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
46
|
-
* minimum require version of node is 10.13
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## 4.1.1 (2018-09-24)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
### Bug Fixes
|
|
54
|
-
|
|
55
|
-
* postcss-normalize-unicode add browserslist to dependencies ([#577](https://github.com/cssnano/cssnano/issues/577)) ([39ec020](https://github.com/cssnano/cssnano/commit/39ec020d9d6fc6ed72bf8de6e856752726d4fb51))
|
|
56
|
-
* **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
|
package/dist/index.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _browserslist = _interopRequireDefault(require("browserslist"));
|
|
9
|
-
|
|
10
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const regexLowerCaseUPrefix = /^u(?=\+)/;
|
|
15
|
-
|
|
16
|
-
function unicode(range) {
|
|
17
|
-
const values = range.slice(2).split('-');
|
|
18
|
-
|
|
19
|
-
if (values.length < 2) {
|
|
20
|
-
return range;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const left = values[0].split('');
|
|
24
|
-
const right = values[1].split('');
|
|
25
|
-
|
|
26
|
-
if (left.length !== right.length) {
|
|
27
|
-
return range;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let questionCounter = 0;
|
|
31
|
-
const merged = left.reduce((group, value, index) => {
|
|
32
|
-
if (group === false) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (value === right[index] && !questionCounter) {
|
|
37
|
-
return group + value;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (value === '0' && right[index] === 'f') {
|
|
41
|
-
questionCounter++;
|
|
42
|
-
return group + '?';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return false;
|
|
46
|
-
}, 'u+'); // The maximum number of wildcard characters (?) for ranges is 5.
|
|
47
|
-
|
|
48
|
-
if (merged && questionCounter < 6) {
|
|
49
|
-
return merged;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return range;
|
|
53
|
-
}
|
|
54
|
-
/*
|
|
55
|
-
* IE and Edge before 16 version ignore the unicode-range if the 'U' is lowercase
|
|
56
|
-
*
|
|
57
|
-
* https://caniuse.com/#search=unicode-range
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function hasLowerCaseUPrefixBug(browser) {
|
|
62
|
-
return ~(0, _browserslist.default)('ie <=11, edge <= 15').indexOf(browser);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function transform(value, isLegacy = false) {
|
|
66
|
-
return (0, _postcssValueParser.default)(value).walk(child => {
|
|
67
|
-
if (child.type === 'unicode-range') {
|
|
68
|
-
const transformed = unicode(child.value.toLowerCase());
|
|
69
|
-
child.value = isLegacy ? transformed.replace(regexLowerCaseUPrefix, 'U') : transformed;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return false;
|
|
73
|
-
}).toString();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function pluginCreator() {
|
|
77
|
-
return {
|
|
78
|
-
postcssPlugin: 'postcss-normalize-unicode',
|
|
79
|
-
|
|
80
|
-
prepare(result) {
|
|
81
|
-
const cache = {};
|
|
82
|
-
const resultOpts = result.opts || {};
|
|
83
|
-
const browsers = (0, _browserslist.default)(null, {
|
|
84
|
-
stats: resultOpts.stats,
|
|
85
|
-
path: __dirname,
|
|
86
|
-
env: resultOpts.env
|
|
87
|
-
});
|
|
88
|
-
const isLegacy = browsers.some(hasLowerCaseUPrefixBug);
|
|
89
|
-
return {
|
|
90
|
-
OnceExit(css) {
|
|
91
|
-
css.walkDecls(/^unicode-range$/i, decl => {
|
|
92
|
-
const value = decl.value;
|
|
93
|
-
|
|
94
|
-
if (cache[value]) {
|
|
95
|
-
decl.value = cache[value];
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const newValue = transform(value, isLegacy);
|
|
100
|
-
decl.value = newValue;
|
|
101
|
-
cache[value] = newValue;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
pluginCreator.postcss = true;
|
|
112
|
-
var _default = pluginCreator;
|
|
113
|
-
exports.default = _default;
|
|
114
|
-
module.exports = exports.default;
|