display-flex.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  4. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  5. var flexSpec = require('./flex-spec');
  6. var OldValue = require('../old-value');
  7. var Value = require('../value');
  8. var DisplayFlex = function (_Value) {
  9. _inherits(DisplayFlex, _Value);
  10. function DisplayFlex(name, prefixes) {
  11. _classCallCheck(this, DisplayFlex);
  12. var _this = _possibleConstructorReturn(this, _Value.call(this, name, prefixes));
  13. if (name === 'display-flex') {
  14. _this.name = 'flex';
  15. }
  16. return _this;
  17. }
  18. /**
  19. * Faster check for flex value
  20. */
  21. DisplayFlex.prototype.check = function check(decl) {
  22. return decl.prop === 'display' && decl.value === this.name;
  23. };
  24. /**
  25. * Return value by spec
  26. */
  27. DisplayFlex.prototype.prefixed = function prefixed(prefix) {
  28. var spec = void 0,
  29. value = void 0;
  30. var _flexSpec = flexSpec(prefix);
  31. spec = _flexSpec[0];
  32. prefix = _flexSpec[1];
  33. if (spec === 2009) {
  34. if (this.name === 'flex') {
  35. value = 'box';
  36. } else {
  37. value = 'inline-box';
  38. }
  39. } else if (spec === 2012) {
  40. if (this.name === 'flex') {
  41. value = 'flexbox';
  42. } else {
  43. value = 'inline-flexbox';
  44. }
  45. } else if (spec === 'final') {
  46. value = this.name;
  47. }
  48. return prefix + value;
  49. };
  50. /**
  51. * Add prefix to value depend on flebox spec version
  52. */
  53. DisplayFlex.prototype.replace = function replace(string, prefix) {
  54. return this.prefixed(prefix);
  55. };
  56. /**
  57. * Change value for old specs
  58. */
  59. DisplayFlex.prototype.old = function old(prefix) {
  60. var prefixed = this.prefixed(prefix);
  61. if (!prefixed) return undefined;
  62. return new OldValue(this.name, prefixed);
  63. };
  64. return DisplayFlex;
  65. }(Value);
  66. Object.defineProperty(DisplayFlex, 'names', {
  67. enumerable: true,
  68. writable: true,
  69. value: ['display-flex', 'inline-flex']
  70. });
  71. module.exports = DisplayFlex;