source: trip-planner-front/node_modules/postcss-normalize-unicode/dist/index.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[6a3a178]1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _browserslist = _interopRequireDefault(require("browserslist"));
9
10var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14const regexLowerCaseUPrefix = /^u(?=\+)/;
15
16function 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
61function hasLowerCaseUPrefixBug(browser) {
62 return ~(0, _browserslist.default)('ie <=11, edge <= 15').indexOf(browser);
63}
64
65function 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
76function 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
111pluginCreator.postcss = true;
112var _default = pluginCreator;
113exports.default = _default;
114module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.