UNPKG

776 BJavaScriptView Raw
1module.exports = (el, $) => {
2 let i;
3 let style = [];
4
5 for (i in el.styleProps) {
6
7 // add !important
8 if (typeof el.styleProps[i].selector.spec !== 'undefined') {
9 if (el.styleProps[i].selector.spec[0] === 2) {
10 el.styleProps[i].value += ' !important';
11 }
12 }
13 style.push(`${el.styleProps[i].prop}: ${el.styleProps[i].value.replace(/["]/g, '\'')};`);
14 }
15
16 // sorting will arrange styles like padding: before padding-bottom: which will preserve the expected styling
17 style = style.sort((a, b) => {
18 const aProp = a.split(':')[0];
19 const bProp = b.split(':')[0];
20
21 return (aProp > bProp ? 1 : aProp < bProp ? -1 : 0);
22 });
23
24 $(el).attr('style', style.join(' '));
25};