display-flex.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 = /*#__PURE__*/function (_Value) {
  9. _inheritsLoose(DisplayFlex, _Value);
  10. function DisplayFlex(name, prefixes) {
  11. var _this;
  12. _this = _Value.call(this, name, prefixes) || this;
  13. if (name === 'display-flex') {
  14. _this.name = 'flex';
  15. }
  16. return _this;
  17. }
  18. /**
  19. * Faster check for flex value
  20. */
  21. var _proto = DisplayFlex.prototype;
  22. _proto.check = function check(decl) {
  23. return decl.prop === 'display' && decl.value === this.name;
  24. }
  25. /**
  26. * Return value by spec
  27. */
  28. ;
  29. _proto.prefixed = function prefixed(prefix) {
  30. var spec, value;
  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. ;
  55. _proto.replace = function replace(string, prefix) {
  56. return this.prefixed(prefix);
  57. }
  58. /**
  59. * Change value for old specs
  60. */
  61. ;
  62. _proto.old = function old(prefix) {
  63. var prefixed = this.prefixed(prefix);
  64. if (!prefixed) return undefined;
  65. return new OldValue(this.name, prefixed);
  66. };
  67. return DisplayFlex;
  68. }(Value);
  69. _defineProperty(DisplayFlex, "names", ['display-flex', 'inline-flex']);
  70. module.exports = DisplayFlex;