display-flex.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  4. function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  5. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  6. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  7. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  8. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  9. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  10. var flexSpec = require('./flex-spec');
  11. var OldValue = require('../old-value');
  12. var Value = require('../value');
  13. var DisplayFlex = /*#__PURE__*/function (_Value) {
  14. _inheritsLoose(DisplayFlex, _Value);
  15. var _super = _createSuper(DisplayFlex);
  16. function DisplayFlex(name, prefixes) {
  17. var _this;
  18. _this = _Value.call(this, name, prefixes) || this;
  19. if (name === 'display-flex') {
  20. _this.name = 'flex';
  21. }
  22. return _this;
  23. }
  24. /**
  25. * Faster check for flex value
  26. */
  27. var _proto = DisplayFlex.prototype;
  28. _proto.check = function check(decl) {
  29. return decl.prop === 'display' && decl.value === this.name;
  30. }
  31. /**
  32. * Return value by spec
  33. */
  34. ;
  35. _proto.prefixed = function prefixed(prefix) {
  36. var spec, value;
  37. var _flexSpec = flexSpec(prefix);
  38. spec = _flexSpec[0];
  39. prefix = _flexSpec[1];
  40. if (spec === 2009) {
  41. if (this.name === 'flex') {
  42. value = 'box';
  43. } else {
  44. value = 'inline-box';
  45. }
  46. } else if (spec === 2012) {
  47. if (this.name === 'flex') {
  48. value = 'flexbox';
  49. } else {
  50. value = 'inline-flexbox';
  51. }
  52. } else if (spec === 'final') {
  53. value = this.name;
  54. }
  55. return prefix + value;
  56. }
  57. /**
  58. * Add prefix to value depend on flebox spec version
  59. */
  60. ;
  61. _proto.replace = function replace(string, prefix) {
  62. return this.prefixed(prefix);
  63. }
  64. /**
  65. * Change value for old specs
  66. */
  67. ;
  68. _proto.old = function old(prefix) {
  69. var prefixed = this.prefixed(prefix);
  70. if (!prefixed) return undefined;
  71. return new OldValue(this.name, prefixed);
  72. };
  73. return DisplayFlex;
  74. }(Value);
  75. _defineProperty(DisplayFlex, "names", ['display-flex', 'inline-flex']);
  76. module.exports = DisplayFlex;