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 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 | const compose = (styleObject) => {
|
53 | if (typeof styleObject !== 'object' || styleObject === null) return undefined;
|
54 |
|
55 |
|
56 | let style1 = '-';
|
57 |
|
58 | style1 += !styleObject.colorize ? '' : 'C';
|
59 |
|
60 | const padding = parseInt(styleObject.padding);
|
61 | style1 += (!padding || padding <= 0 || padding > 99) ? '' : 'P' + (padding > 9 ? padding : '0' + padding);
|
62 |
|
63 | const background = (!styleObject.background || !(typeof styleObject.background === 'string')) ? undefined : styleObject.background.match(re.colorbase)[0];
|
64 | style1 += !background ? '' : 'G_' + background + '_';
|
65 |
|
66 | const detail1 = (!styleObject.detail || !styleObject.detail[0] || !(typeof styleObject.detail[0] === 'string')) ? undefined : styleObject.detail[0].match(re.colorbase)[0];
|
67 | const detail2 = (!styleObject.detail || !styleObject.detail[1] || !(typeof styleObject.detail[1] === 'string')) ? undefined : styleObject.detail[1].match(re.colorbase)[0];
|
68 | if (detail1) {
|
69 | style1 += 'D_' + detail1;
|
70 | if (detail2) {
|
71 | style1 += ',' + detail2;
|
72 | }
|
73 | style1 += '_';
|
74 | }
|
75 |
|
76 | const zoom = (styleObject.zoom === 'x') ? 'x' : parseFloat(styleObject.zoom);
|
77 | style1 += (!zoom || zoom <= 0) ? '' : 'Z' + zoom;
|
78 |
|
79 | let style2 = '';
|
80 |
|
81 | const detailsym = (!styleObject.detailsym || !Array.isArray(styleObject.detailsym)) ? [] : styleObject.detailsym.map((styleObject) => {
|
82 | const index = parseInt(styleObject.index);
|
83 | if (!index || index <= 0 || index > 99) return '';
|
84 | let style = 'D' + (index > 9 ? index : '0' + index);
|
85 | const detail1 = (!styleObject.detail || !styleObject.detail[0]) ? undefined : styleObject.detail[0].match(re.colorbase)[0];
|
86 | const detail2 = (!styleObject.detail || !styleObject.detail[1]) ? undefined : styleObject.detail[1].match(re.colorbase)[0];
|
87 | if (detail1) {
|
88 | style += '_' + detail1;
|
89 | if (detail2) {
|
90 | style += ',' + detail2;
|
91 | }
|
92 | style += '_';
|
93 | }
|
94 | return style;
|
95 | })
|
96 | style2 += detailsym.join('');
|
97 |
|
98 | const zoomsym = (!styleObject.zoomsym || !Array.isArray(styleObject.zoomsym)) ? [] : styleObject.zoomsym.map((styleObject) => {
|
99 | const index = parseInt(styleObject.index);
|
100 | if (!index || index <= 0 || index > 99) return '';
|
101 | let style = 'Z' + (index > 9 ? index : '0' + index);
|
102 | const zoom = parseFloat(styleObject.zoom);
|
103 | style += (!zoom || zoom <= 0) ? '' : ',' + zoom;
|
104 | if (styleObject.offset && (0 in styleObject.offset) && (1 in styleObject.offset)) {
|
105 | const x = parseInt(styleObject.offset[0]) + 500;
|
106 | const y = parseInt(styleObject.offset[1]) + 500;
|
107 | if (x >= 250 && x < 750 && y >= 250 && y < 750) {
|
108 | style += ',' + x + 'x' + y;
|
109 | }
|
110 | }
|
111 | return style;
|
112 | })
|
113 | style2 += zoomsym.join('');
|
114 |
|
115 | let style3 = '';
|
116 | const classes = (!styleObject.classes || !(typeof styleObject.classes === 'string')) ? undefined : styleObject.classes.match(re.classes)[0];
|
117 | style3 += !classes ? '' : classes;
|
118 | const id = (!styleObject.id || !(typeof styleObject.id === 'string')) ? undefined : styleObject.id.match(re.id)[0];
|
119 | style3 += (classes || id) ? '!' : '';
|
120 | style3 += !id ? '' : id + '!';
|
121 |
|
122 | return style1 + ((style2 || style3) ? '-' + style2 : '') + (style3 ? '-' + style3 : '');
|
123 | }
|
124 |
|
125 | export { compose }
|