123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- (function() {
- var AtRule, Browsers, Declaration, Prefixes, Processor, Resolution, Selector, Supports, Value, declsCache, utils, vendor;
- Declaration = require('./declaration');
- Resolution = require('./resolution');
- Processor = require('./processor');
- Supports = require('./supports');
- Browsers = require('./browsers');
- Selector = require('./selector');
- AtRule = require('./at-rule');
- Value = require('./value');
- utils = require('./utils');
- vendor = require('postcss/lib/vendor');
- Selector.hack(require('./hacks/fullscreen'));
- Selector.hack(require('./hacks/placeholder'));
- Declaration.hack(require('./hacks/flex'));
- Declaration.hack(require('./hacks/order'));
- Declaration.hack(require('./hacks/filter'));
- Declaration.hack(require('./hacks/flex-flow'));
- Declaration.hack(require('./hacks/flex-grow'));
- Declaration.hack(require('./hacks/flex-wrap'));
- Declaration.hack(require('./hacks/align-self'));
- Declaration.hack(require('./hacks/flex-basis'));
- Declaration.hack(require('./hacks/align-items'));
- Declaration.hack(require('./hacks/flex-shrink'));
- Declaration.hack(require('./hacks/break-inside'));
- Declaration.hack(require('./hacks/border-image'));
- Declaration.hack(require('./hacks/align-content'));
- Declaration.hack(require('./hacks/border-radius'));
- Declaration.hack(require('./hacks/block-logical'));
- Declaration.hack(require('./hacks/inline-logical'));
- Declaration.hack(require('./hacks/transform-decl'));
- Declaration.hack(require('./hacks/flex-direction'));
- Declaration.hack(require('./hacks/image-rendering'));
- Declaration.hack(require('./hacks/justify-content'));
- Declaration.hack(require('./hacks/background-size'));
- Value.hack(require('./hacks/gradient'));
- Value.hack(require('./hacks/crisp-edges'));
- Value.hack(require('./hacks/flex-values'));
- Value.hack(require('./hacks/display-flex'));
- Value.hack(require('./hacks/filter-value'));
- Value.hack(require('./hacks/fill-available'));
- Value.hack(require('./hacks/transform-value'));
- declsCache = {};
- Prefixes = (function() {
- function Prefixes(_at_data, _at_browsers, _at_options) {
- var _ref;
- this.data = _at_data;
- this.browsers = _at_browsers;
- this.options = _at_options != null ? _at_options : {};
- _ref = this.preprocess(this.select(this.data)), this.add = _ref[0], this.remove = _ref[1];
- this.processor = new Processor(this);
- }
- Prefixes.prototype.transitionProps = ['transition', 'transition-property'];
- Prefixes.prototype.cleaner = function() {
- var empty;
- if (!this.cleanerCache) {
- if (this.browsers.selected.length) {
- empty = new Browsers(this.browsers.data, []);
- this.cleanerCache = new Prefixes(this.data, empty, this.options);
- } else {
- return this;
- }
- }
- return this.cleanerCache;
- };
- Prefixes.prototype.select = function(list) {
- var add, all, data, name, notes, selected;
- selected = {
- add: {},
- remove: {}
- };
- for (name in list) {
- data = list[name];
- add = data.browsers.map(function(i) {
- var params;
- params = i.split(' ');
- return {
- browser: params[0] + ' ' + params[1],
- note: params[2]
- };
- });
- notes = add.filter(function(i) {
- return i.note;
- }).map((function(_this) {
- return function(i) {
- return _this.browsers.prefix(i.browser) + ' ' + i.note;
- };
- })(this));
- notes = utils.uniq(notes);
- add = add.filter((function(_this) {
- return function(i) {
- return _this.browsers.isSelected(i.browser);
- };
- })(this)).map((function(_this) {
- return function(i) {
- var prefix;
- prefix = _this.browsers.prefix(i.browser);
- if (i.note) {
- return prefix + ' ' + i.note;
- } else {
- return prefix;
- }
- };
- })(this));
- add = this.sort(utils.uniq(add));
- all = data.browsers.map((function(_this) {
- return function(i) {
- return _this.browsers.prefix(i);
- };
- })(this));
- if (data.mistakes) {
- all = all.concat(data.mistakes);
- }
- all = all.concat(notes);
- all = utils.uniq(all);
- if (add.length) {
- selected.add[name] = add;
- if (add.length < all.length) {
- selected.remove[name] = all.filter(function(i) {
- return add.indexOf(i) === -1;
- });
- }
- } else {
- selected.remove[name] = all;
- }
- }
- return selected;
- };
- Prefixes.prototype.sort = function(prefixes) {
- return prefixes.sort(function(a, b) {
- var aLength, bLength;
- aLength = utils.removeNote(a).length;
- bLength = utils.removeNote(b).length;
- if (aLength === bLength) {
- return b.length - a.length;
- } else {
- return bLength - aLength;
- }
- });
- };
- Prefixes.prototype.preprocess = function(selected) {
- var add, name, old, olds, prefix, prefixed, prefixes, prop, props, remove, selector, value, values, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _len5, _len6, _m, _n, _o, _ref, _ref1, _ref2;
- add = {
- selectors: [],
- '@supports': new Supports(this)
- };
- _ref = selected.add;
- for (name in _ref) {
- prefixes = _ref[name];
- if (name === '@keyframes' || name === '@viewport') {
- add[name] = new AtRule(name, prefixes, this);
- } else if (name === '@resolution') {
- add[name] = new Resolution(name, prefixes, this);
- } else if (this.data[name].selector) {
- add.selectors.push(Selector.load(name, prefixes, this));
- } else {
- props = this.data[name].transition ? this.transitionProps : this.data[name].props;
- if (props) {
- value = Value.load(name, prefixes, this);
- for (_i = 0, _len = props.length; _i < _len; _i++) {
- prop = props[_i];
- if (!add[prop]) {
- add[prop] = {
- values: []
- };
- }
- add[prop].values.push(value);
- }
- }
- if (!this.data[name].props) {
- values = ((_ref1 = add[name]) != null ? _ref1.values : void 0) || [];
- add[name] = Declaration.load(name, prefixes, this);
- add[name].values = values;
- }
- }
- }
- remove = {
- selectors: []
- };
- _ref2 = selected.remove;
- for (name in _ref2) {
- prefixes = _ref2[name];
- if (this.data[name].selector) {
- selector = Selector.load(name, prefixes);
- for (_j = 0, _len1 = prefixes.length; _j < _len1; _j++) {
- prefix = prefixes[_j];
- remove.selectors.push(selector.old(prefix));
- }
- } else if (name === '@keyframes' || name === '@viewport') {
- for (_k = 0, _len2 = prefixes.length; _k < _len2; _k++) {
- prefix = prefixes[_k];
- prefixed = '@' + prefix + name.slice(1);
- remove[prefixed] = {
- remove: true
- };
- }
- } else if (name === '@resolution') {
- remove[name] = new Resolution(name, prefixes, this);
- } else {
- props = this.data[name].transition ? this.transitionProps : this.data[name].props;
- if (props) {
- value = Value.load(name, [], this);
- for (_l = 0, _len3 = prefixes.length; _l < _len3; _l++) {
- prefix = prefixes[_l];
- old = value.old(prefix);
- if (old) {
- for (_m = 0, _len4 = props.length; _m < _len4; _m++) {
- prop = props[_m];
- if (!remove[prop]) {
- remove[prop] = {};
- }
- if (!remove[prop].values) {
- remove[prop].values = [];
- }
- remove[prop].values.push(old);
- }
- }
- }
- }
- if (!this.data[name].props) {
- for (_n = 0, _len5 = prefixes.length; _n < _len5; _n++) {
- prefix = prefixes[_n];
- prop = vendor.unprefixed(name);
- olds = this.decl(name).old(name, prefix);
- for (_o = 0, _len6 = olds.length; _o < _len6; _o++) {
- prefixed = olds[_o];
- if (!remove[prefixed]) {
- remove[prefixed] = {};
- }
- remove[prefixed].remove = true;
- }
- }
- }
- }
- }
- return [add, remove];
- };
- Prefixes.prototype.decl = function(prop) {
- var decl;
- decl = declsCache[prop];
- if (decl) {
- return decl;
- } else {
- return declsCache[prop] = Declaration.load(prop);
- }
- };
- Prefixes.prototype.unprefixed = function(prop) {
- prop = vendor.unprefixed(prop);
- return this.decl(prop).normalize(prop);
- };
- Prefixes.prototype.prefixed = function(prop, prefix) {
- prop = vendor.unprefixed(prop);
- return this.decl(prop).prefixed(prop, prefix);
- };
- Prefixes.prototype.values = function(type, prop) {
- var data, global, values, _ref, _ref1;
- data = this[type];
- global = (_ref = data['*']) != null ? _ref.values : void 0;
- values = (_ref1 = data[prop]) != null ? _ref1.values : void 0;
- if (global && values) {
- return utils.uniq(global.concat(values));
- } else {
- return global || values || [];
- }
- };
- Prefixes.prototype.group = function(decl) {
- var checker, index, length, rule, unprefixed;
- rule = decl.parent;
- index = rule.index(decl);
- length = rule.nodes.length;
- unprefixed = this.unprefixed(decl.prop);
- checker = (function(_this) {
- return function(step, callback) {
- var other;
- index += step;
- while (index >= 0 && index < length) {
- other = rule.nodes[index];
- if (other.type === 'decl') {
- if (step === -1 && other.prop === unprefixed) {
- if (!Browsers.withPrefix(other.value)) {
- break;
- }
- }
- if (_this.unprefixed(other.prop) !== unprefixed) {
- break;
- } else if (callback(other) === true) {
- return true;
- }
- if (step === +1 && other.prop === unprefixed) {
- if (!Browsers.withPrefix(other.value)) {
- break;
- }
- }
- }
- index += step;
- }
- return false;
- };
- })(this);
- return {
- up: function(callback) {
- return checker(-1, callback);
- },
- down: function(callback) {
- return checker(+1, callback);
- }
- };
- };
- return Prefixes;
- })();
- module.exports = Prefixes;
- }).call(this);
|