display-flex.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _defaults(subClass, superClass); }
  4. 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; }
  5. var flexSpec = require('./flex-spec');
  6. var OldValue = require('../old-value');
  7. var Value = require('../value');
  8. var DisplayFlex =
  9. /*#__PURE__*/
  10. function (_Value) {
  11. _inheritsLoose(DisplayFlex, _Value);
  12. function DisplayFlex(name, prefixes) {
  13. var _this;
  14. _this = _Value.call(this, name, prefixes) || this;
  15. if (name === 'display-flex') {
  16. _this.name = 'flex';
  17. }
  18. return _this;
  19. }
  20. /**
  21. * Faster check for flex value
  22. */
  23. var _proto = DisplayFlex.prototype;
  24. _proto.check = function check(decl) {
  25. return decl.prop === 'display' && decl.value === this.name;
  26. }
  27. /**
  28. * Return value by spec
  29. */
  30. ;
  31. _proto.prefixed = function prefixed(prefix) {
  32. var spec, value;
  33. var _flexSpec = flexSpec(prefix);
  34. spec = _flexSpec[0];
  35. prefix = _flexSpec[1];
  36. if (spec === 2009) {
  37. if (this.name === 'flex') {
  38. value = 'box';
  39. } else {
  40. value = 'inline-box';
  41. }
  42. } else if (spec === 2012) {
  43. if (this.name === 'flex') {
  44. value = 'flexbox';
  45. } else {
  46. value = 'inline-flexbox';
  47. }
  48. } else if (spec === 'final') {
  49. value = this.name;
  50. }
  51. return prefix + value;
  52. }
  53. /**
  54. * Add prefix to value depend on flebox spec version
  55. */
  56. ;
  57. _proto.replace = function replace(string, prefix) {
  58. return this.prefixed(prefix);
  59. }
  60. /**
  61. * Change value for old specs
  62. */
  63. ;
  64. _proto.old = function old(prefix) {
  65. var prefixed = this.prefixed(prefix);
  66. if (!prefixed) return undefined;
  67. return new OldValue(this.name, prefixed);
  68. };
  69. return DisplayFlex;
  70. }(Value);
  71. _defineProperty(DisplayFlex, "names", ['display-flex', 'inline-flex']);
  72. module.exports = DisplayFlex;