1 | import { Trace } from '../../trace';
|
2 | import { CoreTypes } from '../../core-types';
|
3 | import { Length } from './style-properties';
|
4 | export function cleanupImportantFlags(value, propertyName) {
|
5 | if (typeof value !== 'string') {
|
6 | return '' + value;
|
7 | }
|
8 | const index = value?.indexOf('!important');
|
9 | if (index >= 0) {
|
10 | if (Trace.isEnabled()) {
|
11 | Trace.write(`The !important css rule is currently not supported. Property: ${propertyName}`, Trace.categories.Style, Trace.messageType.warn);
|
12 | }
|
13 | return value.substring(0, index).trim();
|
14 | }
|
15 | return value;
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 | const PARTS_RE = /\s(?![^(]*\))/;
|
21 |
|
22 |
|
23 |
|
24 | const LENGTH_RE = /^-?[0-9]+[a-zA-Z%]*?$/;
|
25 |
|
26 |
|
27 |
|
28 | const isLength = (v) => v === '0' || LENGTH_RE.test(v);
|
29 | export function parseCSSShorthand(value) {
|
30 | const parts = value.trim().split(PARTS_RE);
|
31 | const first = parts[0];
|
32 | if (['', 'none', 'unset'].includes(first)) {
|
33 | return null;
|
34 | }
|
35 | else {
|
36 | const invalidColors = ['inset', 'unset'];
|
37 | const inset = parts.includes('inset');
|
38 | const last = parts[parts.length - 1];
|
39 | let color = 'black';
|
40 | if (first && !isLength(first) && !invalidColors.includes(first)) {
|
41 | color = first;
|
42 | }
|
43 | else if (last && !isLength(last) && !invalidColors.includes(last)) {
|
44 | color = last;
|
45 | }
|
46 | const values = parts
|
47 | .filter((n) => !invalidColors.includes(n))
|
48 | .filter((n) => n !== color)
|
49 | .map((val) => {
|
50 | try {
|
51 | return Length.parse(val);
|
52 | }
|
53 | catch (err) {
|
54 | return CoreTypes.zeroLength;
|
55 | }
|
56 | });
|
57 | return {
|
58 | inset,
|
59 | color,
|
60 | values,
|
61 | };
|
62 | }
|
63 | }
|
64 |
|
\ | No newline at end of file |