source: trip-planner-front/node_modules/postcss-merge-longhand/dist/lib/parseWsc.js@ eed0bf8

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = parseWsc;
7
8var _postcss = require("postcss");
9
10var _validateWsc = require("./validateWsc");
11
12const none = /^\s*(none|medium)(\s+none(\s+(none|currentcolor))?)?\s*$/i;
13const varRE = /(^.*var)(.*\(.*--.*\))(.*)/i;
14
15const varPreserveCase = p => `${p[1].toLowerCase()}${p[2]}${p[3].toLowerCase()}`;
16
17const toLower = v => {
18 const match = varRE.exec(v);
19 return match ? varPreserveCase(match) : v.toLowerCase();
20};
21
22function parseWsc(value) {
23 if (none.test(value)) {
24 return ['medium', 'none', 'currentcolor'];
25 }
26
27 let width, style, color;
28
29 const values = _postcss.list.space(value);
30
31 if (values.length > 1 && (0, _validateWsc.isStyle)(values[1]) && values[0].toLowerCase() === 'none') {
32 values.unshift();
33 width = '0';
34 }
35
36 const unknown = [];
37 values.forEach(v => {
38 if ((0, _validateWsc.isStyle)(v)) {
39 style = toLower(v);
40 } else if ((0, _validateWsc.isWidth)(v)) {
41 width = toLower(v);
42 } else if ((0, _validateWsc.isColor)(v)) {
43 color = toLower(v);
44 } else {
45 unknown.push(v);
46 }
47 });
48
49 if (unknown.length) {
50 if (!width && style && color) {
51 width = unknown.pop();
52 }
53
54 if (width && !style && color) {
55 style = unknown.pop();
56 }
57
58 if (width && style && !color) {
59 color = unknown.pop();
60 }
61 }
62
63 return [width, style, color];
64}
65
66module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.