source: frontend/node_modules/postcss-ordered-values/src/rules/boxShadow.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
1'use strict';
2const { unit } = require('postcss-value-parser');
3const { getArguments } = require('cssnano-utils');
4const addSpace = require('../lib/addSpace');
5const getValue = require('../lib/getValue');
6const mathFunctions = require('../lib/mathfunctions.js');
7const vendorUnprefixed = require('../lib/vendorUnprefixed.js');
8
9// box-shadow: inset? && <length>{2,4} && <color>?
10
11/**
12 * @param {import('postcss-value-parser').ParsedValue} parsed
13 * @return {string}
14 */
15module.exports = function normalizeBoxShadow(parsed) {
16 let args = getArguments(parsed);
17
18 const normalized = normalize(args);
19
20 if (normalized === false) {
21 return parsed.toString();
22 }
23
24 return getValue(normalized);
25};
26/**
27 * @param {import('postcss-value-parser').Node[][]} args
28 * @return {false | import('postcss-value-parser').Node[][]}
29 */
30function normalize(args) {
31 const list = [];
32 let abort = false;
33 for (const arg of args) {
34 /** @type {import('postcss-value-parser').Node[]} */
35 let val = [];
36 /** @type {Record<'inset'|'color', import('postcss-value-parser').Node[]>} */
37 let state = {
38 inset: [],
39 color: [],
40 };
41
42 arg.forEach((node) => {
43 const { type, value } = node;
44
45 if (
46 type === 'function' &&
47 mathFunctions.has(vendorUnprefixed(value.toLowerCase()))
48 ) {
49 abort = true;
50 return;
51 }
52
53 if (type === 'space') {
54 return;
55 }
56
57 if (unit(value)) {
58 val = [...val, node, addSpace()];
59 } else if (value.toLowerCase() === 'inset') {
60 state.inset = [...state.inset, node, addSpace()];
61 } else {
62 state.color = [...state.color, node, addSpace()];
63 }
64 });
65
66 if (abort) {
67 return false;
68 }
69
70 list.push([...state.inset, ...val, ...state.color]);
71 }
72 return list;
73}
Note: See TracBrowser for help on using the repository browser.