1 |
|
2 | import { re } from './style-re';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | const compose = (styleObject) => {
|
33 | if (typeof styleObject !== 'object' || styleObject === null) return undefined;
|
34 |
|
35 |
|
36 | let style1 = '-';
|
37 |
|
38 | style1 += !styleObject.colorize ? '' : 'C';
|
39 |
|
40 | const padding = parseInt(styleObject.padding);
|
41 | style1 += (!padding || padding <= 0 || padding > 99) ? '' : 'P' + (padding > 9 ? padding : '0' + padding);
|
42 |
|
43 | const background = (!styleObject.background || !(typeof styleObject.background === 'string')) ? undefined : styleObject.background.match(re.colorbase)[0];
|
44 | style1 += !background ? '' : 'G_' + background + '_';
|
45 |
|
46 | const detail1 = (!styleObject.detail || !styleObject.detail[0] || !(typeof styleObject.detail[0] === 'string')) ? undefined : styleObject.detail[0].match(re.colorbase)[0];
|
47 | const detail2 = (!styleObject.detail || !styleObject.detail[1] || !(typeof styleObject.detail[1] === 'string')) ? undefined : styleObject.detail[1].match(re.colorbase)[0];
|
48 | if (detail1) {
|
49 | style1 += 'D_' + detail1;
|
50 | if (detail2) {
|
51 | style1 += ',' + detail2;
|
52 | }
|
53 | style1 += '_';
|
54 | }
|
55 |
|
56 | const zoom = (styleObject.zoom === 'x') ? 'x' : parseFloat(styleObject.zoom);
|
57 | style1 += (!zoom || zoom <= 0) ? '' : 'Z' + zoom;
|
58 |
|
59 | let style2 = '';
|
60 |
|
61 | const detailsym = (!styleObject.detailsym || !Array.isArray(styleObject.detailsym)) ? [] : styleObject.detailsym.map((styleObject) => {
|
62 | const index = parseInt(styleObject.index);
|
63 | if (!index || index <= 0 || index > 99) return '';
|
64 | let style = 'D' + (index > 9 ? index : '0' + index);
|
65 | const detail1 = (!styleObject.detail || !styleObject.detail[0]) ? undefined : styleObject.detail[0].match(re.colorbase)[0];
|
66 | const detail2 = (!styleObject.detail || !styleObject.detail[1]) ? undefined : styleObject.detail[1].match(re.colorbase)[0];
|
67 | if (detail1) {
|
68 | style += '_' + detail1;
|
69 | if (detail2) {
|
70 | style += ',' + detail2;
|
71 | }
|
72 | style += '_';
|
73 | }
|
74 | return style;
|
75 | })
|
76 | style2 += detailsym.join('');
|
77 |
|
78 | let style3 = '';
|
79 | const classes = (!styleObject.classes || !(typeof styleObject.classes === 'string')) ? undefined : styleObject.classes.match(re.classes)[0];
|
80 | style3 += !classes ? '' : classes;
|
81 | const id = (!styleObject.id || !(typeof styleObject.id === 'string')) ? undefined : styleObject.id.match(re.id)[0];
|
82 | style3 += (classes || id) ? '!' : '';
|
83 | style3 += !id ? '' : id + '!';
|
84 |
|
85 | return style1 + ((style2 || style3) ? '-' + style2 : '') + (style3 ? '-' + style3 : '');
|
86 | }
|
87 |
|
88 | export { compose }
|