Front end of the Slack clone application.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. var Declaration = require('./declaration');
  4. var Resolution = require('./resolution');
  5. var Transition = require('./transition');
  6. var Processor = require('./processor');
  7. var Supports = require('./supports');
  8. var Browsers = require('./browsers');
  9. var Selector = require('./selector');
  10. var AtRule = require('./at-rule');
  11. var Value = require('./value');
  12. var utils = require('./utils');
  13. var vendor = require('postcss').vendor;
  14. Selector.hack(require('./hacks/fullscreen'));
  15. Selector.hack(require('./hacks/placeholder'));
  16. Declaration.hack(require('./hacks/flex'));
  17. Declaration.hack(require('./hacks/order'));
  18. Declaration.hack(require('./hacks/filter'));
  19. Declaration.hack(require('./hacks/grid-end'));
  20. Declaration.hack(require('./hacks/animation'));
  21. Declaration.hack(require('./hacks/flex-flow'));
  22. Declaration.hack(require('./hacks/flex-grow'));
  23. Declaration.hack(require('./hacks/flex-wrap'));
  24. Declaration.hack(require('./hacks/grid-area'));
  25. Declaration.hack(require('./hacks/grid-start'));
  26. Declaration.hack(require('./hacks/align-self'));
  27. Declaration.hack(require('./hacks/appearance'));
  28. Declaration.hack(require('./hacks/flex-basis'));
  29. Declaration.hack(require('./hacks/mask-border'));
  30. Declaration.hack(require('./hacks/align-items'));
  31. Declaration.hack(require('./hacks/flex-shrink'));
  32. Declaration.hack(require('./hacks/break-props'));
  33. Declaration.hack(require('./hacks/writing-mode'));
  34. Declaration.hack(require('./hacks/border-image'));
  35. Declaration.hack(require('./hacks/align-content'));
  36. Declaration.hack(require('./hacks/border-radius'));
  37. Declaration.hack(require('./hacks/block-logical'));
  38. Declaration.hack(require('./hacks/grid-template'));
  39. Declaration.hack(require('./hacks/inline-logical'));
  40. Declaration.hack(require('./hacks/grid-row-align'));
  41. Declaration.hack(require('./hacks/transform-decl'));
  42. Declaration.hack(require('./hacks/flex-direction'));
  43. Declaration.hack(require('./hacks/image-rendering'));
  44. Declaration.hack(require('./hacks/text-decoration'));
  45. Declaration.hack(require('./hacks/justify-content'));
  46. Declaration.hack(require('./hacks/background-size'));
  47. Declaration.hack(require('./hacks/grid-row-column'));
  48. Declaration.hack(require('./hacks/grid-rows-columns'));
  49. Declaration.hack(require('./hacks/grid-column-align'));
  50. Declaration.hack(require('./hacks/grid-template-areas'));
  51. Declaration.hack(require('./hacks/text-emphasis-position'));
  52. Value.hack(require('./hacks/gradient'));
  53. Value.hack(require('./hacks/intrinsic'));
  54. Value.hack(require('./hacks/pixelated'));
  55. Value.hack(require('./hacks/image-set'));
  56. Value.hack(require('./hacks/cross-fade'));
  57. Value.hack(require('./hacks/display-flex'));
  58. Value.hack(require('./hacks/display-grid'));
  59. Value.hack(require('./hacks/filter-value'));
  60. var declsCache = {};
  61. var Prefixes = function () {
  62. function Prefixes(data, browsers) {
  63. var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  64. _classCallCheck(this, Prefixes);
  65. this.data = data;
  66. this.browsers = browsers;
  67. this.options = options;
  68. var _preprocess = this.preprocess(this.select(this.data));
  69. this.add = _preprocess[0];
  70. this.remove = _preprocess[1];
  71. this.transition = new Transition(this);
  72. this.processor = new Processor(this);
  73. }
  74. /**
  75. * Return clone instance to remove all prefixes
  76. */
  77. Prefixes.prototype.cleaner = function cleaner() {
  78. if (this.cleanerCache) {
  79. return this.cleanerCache;
  80. }
  81. if (this.browsers.selected.length) {
  82. var empty = new Browsers(this.browsers.data, []);
  83. this.cleanerCache = new Prefixes(this.data, empty, this.options);
  84. } else {
  85. return this;
  86. }
  87. return this.cleanerCache;
  88. };
  89. /**
  90. * Select prefixes from data, which is necessary for selected browsers
  91. */
  92. Prefixes.prototype.select = function select(list) {
  93. var _this = this;
  94. var selected = { add: {}, remove: {} };
  95. var _loop = function _loop(name) {
  96. var data = list[name];
  97. var add = data.browsers.map(function (i) {
  98. var params = i.split(' ');
  99. return {
  100. browser: params[0] + ' ' + params[1],
  101. note: params[2]
  102. };
  103. });
  104. var notes = add.filter(function (i) {
  105. return i.note;
  106. }).map(function (i) {
  107. return _this.browsers.prefix(i.browser) + ' ' + i.note;
  108. });
  109. notes = utils.uniq(notes);
  110. add = add.filter(function (i) {
  111. return _this.browsers.isSelected(i.browser);
  112. }).map(function (i) {
  113. var prefix = _this.browsers.prefix(i.browser);
  114. if (i.note) {
  115. return prefix + ' ' + i.note;
  116. } else {
  117. return prefix;
  118. }
  119. });
  120. add = _this.sort(utils.uniq(add));
  121. if (_this.options.flexbox === 'no-2009') {
  122. add = add.filter(function (i) {
  123. return i.indexOf('2009') === -1;
  124. });
  125. }
  126. var all = data.browsers.map(function (i) {
  127. return _this.browsers.prefix(i);
  128. });
  129. if (data.mistakes) {
  130. all = all.concat(data.mistakes);
  131. }
  132. all = all.concat(notes);
  133. all = utils.uniq(all);
  134. if (add.length) {
  135. selected.add[name] = add;
  136. if (add.length < all.length) {
  137. selected.remove[name] = all.filter(function (i) {
  138. return add.indexOf(i) === -1;
  139. });
  140. }
  141. } else {
  142. selected.remove[name] = all;
  143. }
  144. };
  145. for (var name in list) {
  146. _loop(name);
  147. }
  148. return selected;
  149. };
  150. /**
  151. * Sort vendor prefixes
  152. */
  153. Prefixes.prototype.sort = function sort(prefixes) {
  154. return prefixes.sort(function (a, b) {
  155. var aLength = utils.removeNote(a).length;
  156. var bLength = utils.removeNote(b).length;
  157. if (aLength === bLength) {
  158. return b.length - a.length;
  159. } else {
  160. return bLength - aLength;
  161. }
  162. });
  163. };
  164. /**
  165. * Cache prefixes data to fast CSS processing
  166. */
  167. Prefixes.prototype.preprocess = function preprocess(selected) {
  168. var add = {
  169. 'selectors': [],
  170. '@supports': new Supports(Prefixes, this)
  171. };
  172. for (var name in selected.add) {
  173. var prefixes = selected.add[name];
  174. if (name === '@keyframes' || name === '@viewport') {
  175. add[name] = new AtRule(name, prefixes, this);
  176. } else if (name === '@resolution') {
  177. add[name] = new Resolution(name, prefixes, this);
  178. } else if (this.data[name].selector) {
  179. add.selectors.push(Selector.load(name, prefixes, this));
  180. } else {
  181. var props = this.data[name].props;
  182. if (props) {
  183. var value = Value.load(name, prefixes, this);
  184. for (var _iterator = props, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
  185. var _ref;
  186. if (_isArray) {
  187. if (_i >= _iterator.length) break;
  188. _ref = _iterator[_i++];
  189. } else {
  190. _i = _iterator.next();
  191. if (_i.done) break;
  192. _ref = _i.value;
  193. }
  194. var prop = _ref;
  195. if (!add[prop]) {
  196. add[prop] = { values: [] };
  197. }
  198. add[prop].values.push(value);
  199. }
  200. } else {
  201. var values = add[name] && add[name].values || [];
  202. add[name] = Declaration.load(name, prefixes, this);
  203. add[name].values = values;
  204. }
  205. }
  206. }
  207. var remove = { selectors: [] };
  208. for (var _name in selected.remove) {
  209. var _prefixes = selected.remove[_name];
  210. if (this.data[_name].selector) {
  211. var selector = Selector.load(_name, _prefixes);
  212. for (var _iterator2 = _prefixes, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
  213. var _ref2;
  214. if (_isArray2) {
  215. if (_i2 >= _iterator2.length) break;
  216. _ref2 = _iterator2[_i2++];
  217. } else {
  218. _i2 = _iterator2.next();
  219. if (_i2.done) break;
  220. _ref2 = _i2.value;
  221. }
  222. var prefix = _ref2;
  223. remove.selectors.push(selector.old(prefix));
  224. }
  225. } else if (_name === '@keyframes' || _name === '@viewport') {
  226. for (var _iterator3 = _prefixes, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
  227. var _ref3;
  228. if (_isArray3) {
  229. if (_i3 >= _iterator3.length) break;
  230. _ref3 = _iterator3[_i3++];
  231. } else {
  232. _i3 = _iterator3.next();
  233. if (_i3.done) break;
  234. _ref3 = _i3.value;
  235. }
  236. var _prefix = _ref3;
  237. var prefixed = '@' + _prefix + _name.slice(1);
  238. remove[prefixed] = { remove: true };
  239. }
  240. } else if (_name === '@resolution') {
  241. remove[_name] = new Resolution(_name, _prefixes, this);
  242. } else {
  243. var _props = this.data[_name].props;
  244. if (_props) {
  245. var _value = Value.load(_name, [], this);
  246. for (var _iterator4 = _prefixes, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : _iterator4[Symbol.iterator]();;) {
  247. var _ref4;
  248. if (_isArray4) {
  249. if (_i4 >= _iterator4.length) break;
  250. _ref4 = _iterator4[_i4++];
  251. } else {
  252. _i4 = _iterator4.next();
  253. if (_i4.done) break;
  254. _ref4 = _i4.value;
  255. }
  256. var _prefix2 = _ref4;
  257. var old = _value.old(_prefix2);
  258. if (old) {
  259. for (var _iterator5 = _props, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : _iterator5[Symbol.iterator]();;) {
  260. var _ref5;
  261. if (_isArray5) {
  262. if (_i5 >= _iterator5.length) break;
  263. _ref5 = _iterator5[_i5++];
  264. } else {
  265. _i5 = _iterator5.next();
  266. if (_i5.done) break;
  267. _ref5 = _i5.value;
  268. }
  269. var _prop = _ref5;
  270. if (!remove[_prop]) {
  271. remove[_prop] = {};
  272. }
  273. if (!remove[_prop].values) {
  274. remove[_prop].values = [];
  275. }
  276. remove[_prop].values.push(old);
  277. }
  278. }
  279. }
  280. } else {
  281. for (var _iterator6 = _prefixes, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : _iterator6[Symbol.iterator]();;) {
  282. var _ref6;
  283. if (_isArray6) {
  284. if (_i6 >= _iterator6.length) break;
  285. _ref6 = _iterator6[_i6++];
  286. } else {
  287. _i6 = _iterator6.next();
  288. if (_i6.done) break;
  289. _ref6 = _i6.value;
  290. }
  291. var _prefix3 = _ref6;
  292. var olds = this.decl(_name).old(_name, _prefix3);
  293. if (_name === 'align-self') {
  294. var a = add[_name] && add[_name].prefixes;
  295. if (a) {
  296. if (_prefix3 === '-webkit- 2009' && a.indexOf('-webkit-') !== -1) {
  297. continue;
  298. } else if (_prefix3 === '-webkit-' && a.indexOf('-webkit- 2009') !== -1) {
  299. continue;
  300. }
  301. }
  302. }
  303. for (var _iterator7 = olds, _isArray7 = Array.isArray(_iterator7), _i7 = 0, _iterator7 = _isArray7 ? _iterator7 : _iterator7[Symbol.iterator]();;) {
  304. var _ref7;
  305. if (_isArray7) {
  306. if (_i7 >= _iterator7.length) break;
  307. _ref7 = _iterator7[_i7++];
  308. } else {
  309. _i7 = _iterator7.next();
  310. if (_i7.done) break;
  311. _ref7 = _i7.value;
  312. }
  313. var _prefixed = _ref7;
  314. if (!remove[_prefixed]) {
  315. remove[_prefixed] = {};
  316. }
  317. remove[_prefixed].remove = true;
  318. }
  319. }
  320. }
  321. }
  322. }
  323. return [add, remove];
  324. };
  325. /**
  326. * Declaration loader with caching
  327. */
  328. Prefixes.prototype.decl = function decl(prop) {
  329. var decl = declsCache[prop];
  330. if (decl) {
  331. return decl;
  332. } else {
  333. declsCache[prop] = Declaration.load(prop);
  334. return declsCache[prop];
  335. }
  336. };
  337. /**
  338. * Return unprefixed version of property
  339. */
  340. Prefixes.prototype.unprefixed = function unprefixed(prop) {
  341. var value = this.normalize(vendor.unprefixed(prop));
  342. if (value === 'flex-direction') {
  343. value = 'flex-flow';
  344. }
  345. return value;
  346. };
  347. /**
  348. * Normalize prefix for remover
  349. */
  350. Prefixes.prototype.normalize = function normalize(prop) {
  351. return this.decl(prop).normalize(prop);
  352. };
  353. /**
  354. * Return prefixed version of property
  355. */
  356. Prefixes.prototype.prefixed = function prefixed(prop, prefix) {
  357. prop = vendor.unprefixed(prop);
  358. return this.decl(prop).prefixed(prop, prefix);
  359. };
  360. /**
  361. * Return values, which must be prefixed in selected property
  362. */
  363. Prefixes.prototype.values = function values(type, prop) {
  364. var data = this[type];
  365. var global = data['*'] && data['*'].values;
  366. var values = data[prop] && data[prop].values;
  367. if (global && values) {
  368. return utils.uniq(global.concat(values));
  369. } else {
  370. return global || values || [];
  371. }
  372. };
  373. /**
  374. * Group declaration by unprefixed property to check them
  375. */
  376. Prefixes.prototype.group = function group(decl) {
  377. var _this2 = this;
  378. var rule = decl.parent;
  379. var index = rule.index(decl);
  380. var length = rule.nodes.length;
  381. var unprefixed = this.unprefixed(decl.prop);
  382. var checker = function checker(step, callback) {
  383. index += step;
  384. while (index >= 0 && index < length) {
  385. var other = rule.nodes[index];
  386. if (other.type === 'decl') {
  387. if (step === -1 && other.prop === unprefixed) {
  388. if (!Browsers.withPrefix(other.value)) {
  389. break;
  390. }
  391. }
  392. if (_this2.unprefixed(other.prop) !== unprefixed) {
  393. break;
  394. } else if (callback(other) === true) {
  395. return true;
  396. }
  397. if (step === +1 && other.prop === unprefixed) {
  398. if (!Browsers.withPrefix(other.value)) {
  399. break;
  400. }
  401. }
  402. }
  403. index += step;
  404. }
  405. return false;
  406. };
  407. return {
  408. up: function up(callback) {
  409. return checker(-1, callback);
  410. },
  411. down: function down(callback) {
  412. return checker(+1, callback);
  413. }
  414. };
  415. };
  416. return Prefixes;
  417. }();
  418. module.exports = Prefixes;