Без опису

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. (function() {
  2. var AtRule, Browsers, Declaration, Prefixes, Processor, Resolution, Selector, Supports, Value, declsCache, utils, vendor;
  3. Declaration = require('./declaration');
  4. Resolution = require('./resolution');
  5. Processor = require('./processor');
  6. Supports = require('./supports');
  7. Browsers = require('./browsers');
  8. Selector = require('./selector');
  9. AtRule = require('./at-rule');
  10. Value = require('./value');
  11. utils = require('./utils');
  12. vendor = require('postcss/lib/vendor');
  13. Selector.hack(require('./hacks/fullscreen'));
  14. Selector.hack(require('./hacks/placeholder'));
  15. Declaration.hack(require('./hacks/flex'));
  16. Declaration.hack(require('./hacks/order'));
  17. Declaration.hack(require('./hacks/filter'));
  18. Declaration.hack(require('./hacks/flex-flow'));
  19. Declaration.hack(require('./hacks/flex-grow'));
  20. Declaration.hack(require('./hacks/flex-wrap'));
  21. Declaration.hack(require('./hacks/appearance'));
  22. Declaration.hack(require('./hacks/align-self'));
  23. Declaration.hack(require('./hacks/flex-basis'));
  24. Declaration.hack(require('./hacks/align-items'));
  25. Declaration.hack(require('./hacks/flex-shrink'));
  26. Declaration.hack(require('./hacks/break-inside'));
  27. Declaration.hack(require('./hacks/border-image'));
  28. Declaration.hack(require('./hacks/align-content'));
  29. Declaration.hack(require('./hacks/border-radius'));
  30. Declaration.hack(require('./hacks/block-logical'));
  31. Declaration.hack(require('./hacks/inline-logical'));
  32. Declaration.hack(require('./hacks/transform-decl'));
  33. Declaration.hack(require('./hacks/flex-direction'));
  34. Declaration.hack(require('./hacks/image-rendering'));
  35. Declaration.hack(require('./hacks/justify-content'));
  36. Declaration.hack(require('./hacks/background-size'));
  37. Value.hack(require('./hacks/gradient'));
  38. Value.hack(require('./hacks/pixelated'));
  39. Value.hack(require('./hacks/flex-values'));
  40. Value.hack(require('./hacks/display-flex'));
  41. Value.hack(require('./hacks/filter-value'));
  42. Value.hack(require('./hacks/fill-available'));
  43. Value.hack(require('./hacks/transform-value'));
  44. declsCache = {};
  45. Prefixes = (function() {
  46. function Prefixes(data1, browsers, options) {
  47. var ref;
  48. this.data = data1;
  49. this.browsers = browsers;
  50. this.options = options != null ? options : {};
  51. ref = this.preprocess(this.select(this.data)), this.add = ref[0], this.remove = ref[1];
  52. this.processor = new Processor(this);
  53. }
  54. Prefixes.prototype.transitionProps = ['transition', 'transition-property'];
  55. Prefixes.prototype.cleaner = function() {
  56. var empty;
  57. if (!this.cleanerCache) {
  58. if (this.browsers.selected.length) {
  59. empty = new Browsers(this.browsers.data, []);
  60. this.cleanerCache = new Prefixes(this.data, empty, this.options);
  61. } else {
  62. return this;
  63. }
  64. }
  65. return this.cleanerCache;
  66. };
  67. Prefixes.prototype.select = function(list) {
  68. var add, all, data, name, notes, selected;
  69. selected = {
  70. add: {},
  71. remove: {}
  72. };
  73. for (name in list) {
  74. data = list[name];
  75. add = data.browsers.map(function(i) {
  76. var params;
  77. params = i.split(' ');
  78. return {
  79. browser: params[0] + ' ' + params[1],
  80. note: params[2]
  81. };
  82. });
  83. notes = add.filter(function(i) {
  84. return i.note;
  85. }).map((function(_this) {
  86. return function(i) {
  87. return _this.browsers.prefix(i.browser) + ' ' + i.note;
  88. };
  89. })(this));
  90. notes = utils.uniq(notes);
  91. add = add.filter((function(_this) {
  92. return function(i) {
  93. return _this.browsers.isSelected(i.browser);
  94. };
  95. })(this)).map((function(_this) {
  96. return function(i) {
  97. var prefix;
  98. prefix = _this.browsers.prefix(i.browser);
  99. if (i.note) {
  100. return prefix + ' ' + i.note;
  101. } else {
  102. return prefix;
  103. }
  104. };
  105. })(this));
  106. add = this.sort(utils.uniq(add));
  107. all = data.browsers.map((function(_this) {
  108. return function(i) {
  109. return _this.browsers.prefix(i);
  110. };
  111. })(this));
  112. if (data.mistakes) {
  113. all = all.concat(data.mistakes);
  114. }
  115. all = all.concat(notes);
  116. all = utils.uniq(all);
  117. if (add.length) {
  118. selected.add[name] = add;
  119. if (add.length < all.length) {
  120. selected.remove[name] = all.filter(function(i) {
  121. return add.indexOf(i) === -1;
  122. });
  123. }
  124. } else {
  125. selected.remove[name] = all;
  126. }
  127. }
  128. return selected;
  129. };
  130. Prefixes.prototype.sort = function(prefixes) {
  131. return prefixes.sort(function(a, b) {
  132. var aLength, bLength;
  133. aLength = utils.removeNote(a).length;
  134. bLength = utils.removeNote(b).length;
  135. if (aLength === bLength) {
  136. return b.length - a.length;
  137. } else {
  138. return bLength - aLength;
  139. }
  140. });
  141. };
  142. Prefixes.prototype.preprocess = function(selected) {
  143. var add, j, k, l, len, len1, len2, len3, len4, len5, len6, m, n, name, o, old, olds, p, prefix, prefixed, prefixes, prop, props, ref, ref1, ref2, remove, selector, value, values;
  144. add = {
  145. selectors: [],
  146. '@supports': new Supports(this)
  147. };
  148. ref = selected.add;
  149. for (name in ref) {
  150. prefixes = ref[name];
  151. if (name === '@keyframes' || name === '@viewport') {
  152. add[name] = new AtRule(name, prefixes, this);
  153. } else if (name === '@resolution') {
  154. add[name] = new Resolution(name, prefixes, this);
  155. } else if (this.data[name].selector) {
  156. add.selectors.push(Selector.load(name, prefixes, this));
  157. } else {
  158. props = this.data[name].transition ? this.transitionProps : this.data[name].props;
  159. if (props) {
  160. value = Value.load(name, prefixes, this);
  161. for (j = 0, len = props.length; j < len; j++) {
  162. prop = props[j];
  163. if (!add[prop]) {
  164. add[prop] = {
  165. values: []
  166. };
  167. }
  168. add[prop].values.push(value);
  169. }
  170. }
  171. if (!this.data[name].props) {
  172. values = ((ref1 = add[name]) != null ? ref1.values : void 0) || [];
  173. add[name] = Declaration.load(name, prefixes, this);
  174. add[name].values = values;
  175. }
  176. }
  177. }
  178. remove = {
  179. selectors: []
  180. };
  181. ref2 = selected.remove;
  182. for (name in ref2) {
  183. prefixes = ref2[name];
  184. if (this.data[name].selector) {
  185. selector = Selector.load(name, prefixes);
  186. for (k = 0, len1 = prefixes.length; k < len1; k++) {
  187. prefix = prefixes[k];
  188. remove.selectors.push(selector.old(prefix));
  189. }
  190. } else if (name === '@keyframes' || name === '@viewport') {
  191. for (l = 0, len2 = prefixes.length; l < len2; l++) {
  192. prefix = prefixes[l];
  193. prefixed = '@' + prefix + name.slice(1);
  194. remove[prefixed] = {
  195. remove: true
  196. };
  197. }
  198. } else if (name === '@resolution') {
  199. remove[name] = new Resolution(name, prefixes, this);
  200. } else {
  201. props = this.data[name].transition ? this.transitionProps : this.data[name].props;
  202. if (props) {
  203. value = Value.load(name, [], this);
  204. for (m = 0, len3 = prefixes.length; m < len3; m++) {
  205. prefix = prefixes[m];
  206. old = value.old(prefix);
  207. if (old) {
  208. for (n = 0, len4 = props.length; n < len4; n++) {
  209. prop = props[n];
  210. if (!remove[prop]) {
  211. remove[prop] = {};
  212. }
  213. if (!remove[prop].values) {
  214. remove[prop].values = [];
  215. }
  216. remove[prop].values.push(old);
  217. }
  218. }
  219. }
  220. }
  221. if (!this.data[name].props) {
  222. for (o = 0, len5 = prefixes.length; o < len5; o++) {
  223. prefix = prefixes[o];
  224. prop = vendor.unprefixed(name);
  225. olds = this.decl(name).old(name, prefix);
  226. for (p = 0, len6 = olds.length; p < len6; p++) {
  227. prefixed = olds[p];
  228. if (!remove[prefixed]) {
  229. remove[prefixed] = {};
  230. }
  231. remove[prefixed].remove = true;
  232. }
  233. }
  234. }
  235. }
  236. }
  237. return [add, remove];
  238. };
  239. Prefixes.prototype.decl = function(prop) {
  240. var decl;
  241. decl = declsCache[prop];
  242. if (decl) {
  243. return decl;
  244. } else {
  245. return declsCache[prop] = Declaration.load(prop);
  246. }
  247. };
  248. Prefixes.prototype.unprefixed = function(prop) {
  249. prop = vendor.unprefixed(prop);
  250. return this.decl(prop).normalize(prop);
  251. };
  252. Prefixes.prototype.prefixed = function(prop, prefix) {
  253. prop = vendor.unprefixed(prop);
  254. return this.decl(prop).prefixed(prop, prefix);
  255. };
  256. Prefixes.prototype.values = function(type, prop) {
  257. var data, global, ref, ref1, values;
  258. data = this[type];
  259. global = (ref = data['*']) != null ? ref.values : void 0;
  260. values = (ref1 = data[prop]) != null ? ref1.values : void 0;
  261. if (global && values) {
  262. return utils.uniq(global.concat(values));
  263. } else {
  264. return global || values || [];
  265. }
  266. };
  267. Prefixes.prototype.group = function(decl) {
  268. var checker, index, length, rule, unprefixed;
  269. rule = decl.parent;
  270. index = rule.index(decl);
  271. length = rule.nodes.length;
  272. unprefixed = this.unprefixed(decl.prop);
  273. checker = (function(_this) {
  274. return function(step, callback) {
  275. var other;
  276. index += step;
  277. while (index >= 0 && index < length) {
  278. other = rule.nodes[index];
  279. if (other.type === 'decl') {
  280. if (step === -1 && other.prop === unprefixed) {
  281. if (!Browsers.withPrefix(other.value)) {
  282. break;
  283. }
  284. }
  285. if (_this.unprefixed(other.prop) !== unprefixed) {
  286. break;
  287. } else if (callback(other) === true) {
  288. return true;
  289. }
  290. if (step === +1 && other.prop === unprefixed) {
  291. if (!Browsers.withPrefix(other.value)) {
  292. break;
  293. }
  294. }
  295. }
  296. index += step;
  297. }
  298. return false;
  299. };
  300. })(this);
  301. return {
  302. up: function(callback) {
  303. return checker(-1, callback);
  304. },
  305. down: function(callback) {
  306. return checker(+1, callback);
  307. }
  308. };
  309. };
  310. return Prefixes;
  311. })();
  312. module.exports = Prefixes;
  313. }).call(this);