|
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.5 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 | const { unit, stringify } = require('postcss-value-parser');
|
|---|
| 3 | const mathFunctions = require('../lib/mathfunctions.js');
|
|---|
| 4 |
|
|---|
| 5 | // border: <line-width> || <line-style> || <color>
|
|---|
| 6 | // outline: <outline-color> || <outline-style> || <outline-width>
|
|---|
| 7 |
|
|---|
| 8 | const borderWidths = new Set(['thin', 'medium', 'thick']);
|
|---|
| 9 |
|
|---|
| 10 | const borderStyles = new Set([
|
|---|
| 11 | 'none',
|
|---|
| 12 | 'auto', // only in outline-style
|
|---|
| 13 | 'hidden',
|
|---|
| 14 | 'dotted',
|
|---|
| 15 | 'dashed',
|
|---|
| 16 | 'solid',
|
|---|
| 17 | 'double',
|
|---|
| 18 | 'groove',
|
|---|
| 19 | 'ridge',
|
|---|
| 20 | 'inset',
|
|---|
| 21 | 'outset',
|
|---|
| 22 | ]);
|
|---|
| 23 |
|
|---|
| 24 | /**
|
|---|
| 25 | * @param {import('postcss-value-parser').ParsedValue} border
|
|---|
| 26 | * @return {string}
|
|---|
| 27 | */
|
|---|
| 28 | module.exports = function normalizeBorder(border) {
|
|---|
| 29 | const order = { width: '', style: '', color: '' };
|
|---|
| 30 |
|
|---|
| 31 | border.walk((node) => {
|
|---|
| 32 | const { type, value } = node;
|
|---|
| 33 | if (type === 'word') {
|
|---|
| 34 | if (borderStyles.has(value.toLowerCase())) {
|
|---|
| 35 | order.style = value;
|
|---|
| 36 | return false;
|
|---|
| 37 | }
|
|---|
| 38 | if (borderWidths.has(value.toLowerCase()) || unit(value.toLowerCase())) {
|
|---|
| 39 | if (order.width !== '') {
|
|---|
| 40 | order.width = `${order.width} ${value}`;
|
|---|
| 41 | return false;
|
|---|
| 42 | }
|
|---|
| 43 | order.width = value;
|
|---|
| 44 | return false;
|
|---|
| 45 | }
|
|---|
| 46 | order.color = value;
|
|---|
| 47 | return false;
|
|---|
| 48 | }
|
|---|
| 49 | if (type === 'function') {
|
|---|
| 50 | if (mathFunctions.has(value.toLowerCase())) {
|
|---|
| 51 | order.width = stringify(node);
|
|---|
| 52 | } else {
|
|---|
| 53 | order.color = stringify(node);
|
|---|
| 54 | }
|
|---|
| 55 | return false;
|
|---|
| 56 | }
|
|---|
| 57 | });
|
|---|
| 58 |
|
|---|
| 59 | return `${order.width} ${order.style} ${order.color}`.trim();
|
|---|
| 60 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.