flex-direction.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 Declaration = require('../declaration');
  12. var FlexDirection = /*#__PURE__*/function (_Declaration) {
  13. _inheritsLoose(FlexDirection, _Declaration);
  14. var _super = _createSuper(FlexDirection);
  15. function FlexDirection() {
  16. return _Declaration.apply(this, arguments) || this;
  17. }
  18. var _proto = FlexDirection.prototype;
  19. /**
  20. * Return property name by final spec
  21. */
  22. _proto.normalize = function normalize() {
  23. return 'flex-direction';
  24. }
  25. /**
  26. * Use two properties for 2009 spec
  27. */
  28. ;
  29. _proto.insert = function insert(decl, prefix, prefixes) {
  30. var spec;
  31. var _flexSpec = flexSpec(prefix);
  32. spec = _flexSpec[0];
  33. prefix = _flexSpec[1];
  34. if (spec !== 2009) {
  35. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  36. }
  37. var already = decl.parent.some(function (i) {
  38. return i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction';
  39. });
  40. if (already) {
  41. return undefined;
  42. }
  43. var v = decl.value;
  44. var orient, dir;
  45. if (v === 'inherit' || v === 'initial' || v === 'unset') {
  46. orient = v;
  47. dir = v;
  48. } else {
  49. orient = v.includes('row') ? 'horizontal' : 'vertical';
  50. dir = v.includes('reverse') ? 'reverse' : 'normal';
  51. }
  52. var cloned = this.clone(decl);
  53. cloned.prop = prefix + 'box-orient';
  54. cloned.value = orient;
  55. if (this.needCascade(decl)) {
  56. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  57. }
  58. decl.parent.insertBefore(decl, cloned);
  59. cloned = this.clone(decl);
  60. cloned.prop = prefix + 'box-direction';
  61. cloned.value = dir;
  62. if (this.needCascade(decl)) {
  63. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  64. }
  65. return decl.parent.insertBefore(decl, cloned);
  66. }
  67. /**
  68. * Clean two properties for 2009 spec
  69. */
  70. ;
  71. _proto.old = function old(prop, prefix) {
  72. var spec;
  73. var _flexSpec2 = flexSpec(prefix);
  74. spec = _flexSpec2[0];
  75. prefix = _flexSpec2[1];
  76. if (spec === 2009) {
  77. return [prefix + 'box-orient', prefix + 'box-direction'];
  78. } else {
  79. return _Declaration.prototype.old.call(this, prop, prefix);
  80. }
  81. };
  82. return FlexDirection;
  83. }(Declaration);
  84. _defineProperty(FlexDirection, "names", ['flex-direction', 'box-direction', 'box-orient']);
  85. module.exports = FlexDirection;