display-flex.js 3.2 KB

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