[79a0317] | 1 | var DEFAULTS = {
|
---|
| 2 | '*': {
|
---|
| 3 | colors: {
|
---|
| 4 | hexAlpha: false, // 4- and 8-character hex notation
|
---|
| 5 | opacity: true // rgba / hsla
|
---|
| 6 | },
|
---|
| 7 | customUnits: { rpx: false },
|
---|
| 8 | properties: {
|
---|
| 9 | backgroundClipMerging: true, // background-clip to shorthand
|
---|
| 10 | backgroundOriginMerging: true, // background-origin to shorthand
|
---|
| 11 | backgroundSizeMerging: true, // background-size to shorthand
|
---|
| 12 | colors: true, // any kind of color transformations, like `#ff00ff` to `#f0f` or `#fff` into `red`
|
---|
| 13 | ieBangHack: false, // !ie suffix hacks on IE<8
|
---|
| 14 | ieFilters: false, // whether to preserve `filter` and `-ms-filter` properties
|
---|
| 15 | iePrefixHack: false, // underscore / asterisk prefix hacks on IE
|
---|
| 16 | ieSuffixHack: false, // \9 suffix hacks on IE6-9, \0 suffix hack on IE6-11
|
---|
| 17 | merging: true, // merging properties into one
|
---|
| 18 | shorterLengthUnits: false, // optimize pixel units into `pt`, `pc` or `in` units
|
---|
| 19 | spaceAfterClosingBrace: true, // 'url() no-repeat' to 'url()no-repeat'
|
---|
| 20 | urlQuotes: true, // whether to wrap content of `url()` into quotes or not
|
---|
| 21 | zeroUnits: true // 0[unit] -> 0
|
---|
| 22 | },
|
---|
| 23 | selectors: {
|
---|
| 24 | adjacentSpace: false, // div+ nav Android stock browser hack
|
---|
| 25 | ie7Hack: false, // *+html hack
|
---|
| 26 | mergeablePseudoClasses: [
|
---|
| 27 | ':active',
|
---|
| 28 | ':after',
|
---|
| 29 | ':before',
|
---|
| 30 | ':empty',
|
---|
| 31 | ':checked',
|
---|
| 32 | ':disabled',
|
---|
| 33 | ':empty',
|
---|
| 34 | ':enabled',
|
---|
| 35 | ':first-child',
|
---|
| 36 | ':first-letter',
|
---|
| 37 | ':first-line',
|
---|
| 38 | ':first-of-type',
|
---|
| 39 | ':focus',
|
---|
| 40 | ':hover',
|
---|
| 41 | ':lang',
|
---|
| 42 | ':last-child',
|
---|
| 43 | ':last-of-type',
|
---|
| 44 | ':link',
|
---|
| 45 | ':not',
|
---|
| 46 | ':nth-child',
|
---|
| 47 | ':nth-last-child',
|
---|
| 48 | ':nth-last-of-type',
|
---|
| 49 | ':nth-of-type',
|
---|
| 50 | ':only-child',
|
---|
| 51 | ':only-of-type',
|
---|
| 52 | ':root',
|
---|
| 53 | ':target',
|
---|
| 54 | ':visited'
|
---|
| 55 | ], // selectors with these pseudo-classes can be merged as these are universally supported
|
---|
| 56 | mergeablePseudoElements: [
|
---|
| 57 | '::after',
|
---|
| 58 | '::before',
|
---|
| 59 | '::first-letter',
|
---|
| 60 | '::first-line'
|
---|
| 61 | ], // selectors with these pseudo-elements can be merged as these are universally supported
|
---|
| 62 | mergeLimit: 8191, // number of rules that can be safely merged together
|
---|
| 63 | multiplePseudoMerging: true
|
---|
| 64 | },
|
---|
| 65 | units: {
|
---|
| 66 | ch: true,
|
---|
| 67 | in: true,
|
---|
| 68 | pc: true,
|
---|
| 69 | pt: true,
|
---|
| 70 | rem: true,
|
---|
| 71 | vh: true,
|
---|
| 72 | vm: true, // vm is vmin on IE9+ see https://developer.mozilla.org/en-US/docs/Web/CSS/length
|
---|
| 73 | vmax: true,
|
---|
| 74 | vmin: true,
|
---|
| 75 | vw: true
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | };
|
---|
| 79 |
|
---|
| 80 | DEFAULTS.ie11 = merge(DEFAULTS['*'], { properties: { ieSuffixHack: true } });
|
---|
| 81 |
|
---|
| 82 | DEFAULTS.ie10 = merge(DEFAULTS['*'], { properties: { ieSuffixHack: true } });
|
---|
| 83 |
|
---|
| 84 | DEFAULTS.ie9 = merge(DEFAULTS['*'], {
|
---|
| 85 | properties: {
|
---|
| 86 | ieFilters: true,
|
---|
| 87 | ieSuffixHack: true
|
---|
| 88 | }
|
---|
| 89 | });
|
---|
| 90 |
|
---|
| 91 | DEFAULTS.ie8 = merge(DEFAULTS.ie9, {
|
---|
| 92 | colors: { opacity: false },
|
---|
| 93 | properties: {
|
---|
| 94 | backgroundClipMerging: false,
|
---|
| 95 | backgroundOriginMerging: false,
|
---|
| 96 | backgroundSizeMerging: false,
|
---|
| 97 | iePrefixHack: true,
|
---|
| 98 | merging: false
|
---|
| 99 | },
|
---|
| 100 | selectors: {
|
---|
| 101 | mergeablePseudoClasses: [
|
---|
| 102 | ':after',
|
---|
| 103 | ':before',
|
---|
| 104 | ':first-child',
|
---|
| 105 | ':first-letter',
|
---|
| 106 | ':focus',
|
---|
| 107 | ':hover',
|
---|
| 108 | ':visited'
|
---|
| 109 | ],
|
---|
| 110 | mergeablePseudoElements: []
|
---|
| 111 | },
|
---|
| 112 | units: {
|
---|
| 113 | ch: false,
|
---|
| 114 | rem: false,
|
---|
| 115 | vh: false,
|
---|
| 116 | vm: false,
|
---|
| 117 | vmax: false,
|
---|
| 118 | vmin: false,
|
---|
| 119 | vw: false
|
---|
| 120 | }
|
---|
| 121 | });
|
---|
| 122 |
|
---|
| 123 | DEFAULTS.ie7 = merge(DEFAULTS.ie8, {
|
---|
| 124 | properties: { ieBangHack: true },
|
---|
| 125 | selectors: {
|
---|
| 126 | ie7Hack: true,
|
---|
| 127 | mergeablePseudoClasses: [
|
---|
| 128 | ':first-child',
|
---|
| 129 | ':first-letter',
|
---|
| 130 | ':hover',
|
---|
| 131 | ':visited'
|
---|
| 132 | ]
|
---|
| 133 | }
|
---|
| 134 | });
|
---|
| 135 |
|
---|
| 136 | function compatibilityFrom(source) {
|
---|
| 137 | return merge(DEFAULTS['*'], calculateSource(source));
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | function merge(source, target) {
|
---|
| 141 | for (var key in source) {
|
---|
| 142 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
---|
| 143 | var value = source[key];
|
---|
| 144 |
|
---|
| 145 | if (Object.prototype.hasOwnProperty.call(target, key) && typeof value === 'object' && !Array.isArray(value)) {
|
---|
| 146 | target[key] = merge(value, target[key] || {});
|
---|
| 147 | } else {
|
---|
| 148 | target[key] = key in target ? target[key] : value;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 | return target;
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | function calculateSource(source) {
|
---|
| 157 | if (typeof source == 'object') { return source; }
|
---|
| 158 |
|
---|
| 159 | if (!/[,+-]/.test(source)) { return DEFAULTS[source] || DEFAULTS['*']; }
|
---|
| 160 |
|
---|
| 161 | var parts = source.split(',');
|
---|
| 162 | var template = parts[0] in DEFAULTS
|
---|
| 163 | ? DEFAULTS[parts.shift()]
|
---|
| 164 | : DEFAULTS['*'];
|
---|
| 165 |
|
---|
| 166 | source = {};
|
---|
| 167 |
|
---|
| 168 | parts.forEach(function(part) {
|
---|
| 169 | var isAdd = part[0] == '+';
|
---|
| 170 | var key = part.substring(1).split('.');
|
---|
| 171 | var group = key[0];
|
---|
| 172 | var option = key[1];
|
---|
| 173 |
|
---|
| 174 | source[group] = source[group] || {};
|
---|
| 175 | source[group][option] = isAdd;
|
---|
| 176 | });
|
---|
| 177 |
|
---|
| 178 | return merge(template, source);
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | module.exports = compatibilityFrom;
|
---|