123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- var DEFAULTS = {
- '*': {
- colors: {
- hexAlpha: false,
- opacity: true
- },
- customUnits: { rpx: false },
- properties: {
- backgroundClipMerging: true,
- backgroundOriginMerging: true,
- backgroundSizeMerging: true,
- colors: true,
- ieBangHack: false,
- ieFilters: false,
- iePrefixHack: false,
- ieSuffixHack: false,
- merging: true,
- shorterLengthUnits: false,
- spaceAfterClosingBrace: true,
- urlQuotes: true,
- zeroUnits: true
- },
- selectors: {
- adjacentSpace: false,
- ie7Hack: false,
- mergeablePseudoClasses: [
- ':active',
- ':after',
- ':before',
- ':empty',
- ':checked',
- ':disabled',
- ':empty',
- ':enabled',
- ':first-child',
- ':first-letter',
- ':first-line',
- ':first-of-type',
- ':focus',
- ':hover',
- ':lang',
- ':last-child',
- ':last-of-type',
- ':link',
- ':not',
- ':nth-child',
- ':nth-last-child',
- ':nth-last-of-type',
- ':nth-of-type',
- ':only-child',
- ':only-of-type',
- ':root',
- ':target',
- ':visited'
- ],
- mergeablePseudoElements: [
- '::after',
- '::before',
- '::first-letter',
- '::first-line'
- ],
- mergeLimit: 8191,
- multiplePseudoMerging: true
- },
- units: {
- ch: true,
- in: true,
- pc: true,
- pt: true,
- rem: true,
- vh: true,
- vm: true,
- vmax: true,
- vmin: true,
- vw: true
- }
- }
- };
- DEFAULTS.ie11 = merge(DEFAULTS['*'], { properties: { ieSuffixHack: true } });
- DEFAULTS.ie10 = merge(DEFAULTS['*'], { properties: { ieSuffixHack: true } });
- DEFAULTS.ie9 = merge(DEFAULTS['*'], {
- properties: {
- ieFilters: true,
- ieSuffixHack: true
- }
- });
- DEFAULTS.ie8 = merge(DEFAULTS.ie9, {
- colors: { opacity: false },
- properties: {
- backgroundClipMerging: false,
- backgroundOriginMerging: false,
- backgroundSizeMerging: false,
- iePrefixHack: true,
- merging: false
- },
- selectors: {
- mergeablePseudoClasses: [
- ':after',
- ':before',
- ':first-child',
- ':first-letter',
- ':focus',
- ':hover',
- ':visited'
- ],
- mergeablePseudoElements: []
- },
- units: {
- ch: false,
- rem: false,
- vh: false,
- vm: false,
- vmax: false,
- vmin: false,
- vw: false
- }
- });
- DEFAULTS.ie7 = merge(DEFAULTS.ie8, {
- properties: { ieBangHack: true },
- selectors: {
- ie7Hack: true,
- mergeablePseudoClasses: [
- ':first-child',
- ':first-letter',
- ':hover',
- ':visited'
- ]
- }
- });
- function compatibilityFrom(source) {
- return merge(DEFAULTS['*'], calculateSource(source));
- }
- function merge(source, target) {
- for (var key in source) {
- if (Object.prototype.hasOwnProperty.call(source, key)) {
- var value = source[key];
- if (Object.prototype.hasOwnProperty.call(target, key) && typeof value === 'object' && !Array.isArray(value)) {
- target[key] = merge(value, target[key] || {});
- } else {
- target[key] = key in target ? target[key] : value;
- }
- }
- }
- return target;
- }
- function calculateSource(source) {
- if (typeof source == 'object') { return source; }
- if (!/[,+-]/.test(source)) { return DEFAULTS[source] || DEFAULTS['*']; }
- var parts = source.split(',');
- var template = parts[0] in DEFAULTS
- ? DEFAULTS[parts.shift()]
- : DEFAULTS['*'];
- source = {};
- parts.forEach(function(part) {
- var isAdd = part[0] == '+';
- var key = part.substring(1).split('.');
- var group = key[0];
- var option = key[1];
- source[group] = source[group] || {};
- source[group][option] = isAdd;
- });
- return merge(template, source);
- }
- module.exports = compatibilityFrom;
|