flex-direction.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. 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; }
  4. 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) : subClass.__proto__ = superClass; }
  5. var flexSpec = require('./flex-spec');
  6. var Declaration = require('../declaration');
  7. var FlexDirection = function (_Declaration) {
  8. _inherits(FlexDirection, _Declaration);
  9. function FlexDirection() {
  10. _classCallCheck(this, FlexDirection);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Return property name by final spec
  15. */
  16. FlexDirection.prototype.normalize = function normalize() {
  17. return 'flex-direction';
  18. };
  19. /**
  20. * Use two properties for 2009 spec
  21. */
  22. FlexDirection.prototype.insert = function insert(decl, prefix, prefixes) {
  23. var spec = void 0;
  24. var _flexSpec = flexSpec(prefix);
  25. spec = _flexSpec[0];
  26. prefix = _flexSpec[1];
  27. if (spec !== 2009) {
  28. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  29. } else {
  30. var already = decl.parent.some(function (i) {
  31. return i.prop === prefix + 'box-orient' || i.prop === prefix + 'box-direction';
  32. });
  33. if (already) {
  34. return undefined;
  35. }
  36. var v = decl.value;
  37. var orient = void 0,
  38. dir = void 0;
  39. if (v === 'inherit' || v === 'initial' || v === 'unset') {
  40. orient = v;
  41. dir = v;
  42. } else {
  43. orient = v.indexOf('row') !== -1 ? 'horizontal' : 'vertical';
  44. dir = v.indexOf('reverse') !== -1 ? 'reverse' : 'normal';
  45. }
  46. var cloned = this.clone(decl);
  47. cloned.prop = prefix + 'box-orient';
  48. cloned.value = orient;
  49. if (this.needCascade(decl)) {
  50. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  51. }
  52. decl.parent.insertBefore(decl, cloned);
  53. cloned = this.clone(decl);
  54. cloned.prop = prefix + 'box-direction';
  55. cloned.value = dir;
  56. if (this.needCascade(decl)) {
  57. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  58. }
  59. return decl.parent.insertBefore(decl, cloned);
  60. }
  61. };
  62. /**
  63. * Clean two properties for 2009 spec
  64. */
  65. FlexDirection.prototype.old = function old(prop, prefix) {
  66. var spec = void 0;
  67. var _flexSpec2 = flexSpec(prefix);
  68. spec = _flexSpec2[0];
  69. prefix = _flexSpec2[1];
  70. if (spec === 2009) {
  71. return [prefix + 'box-orient', prefix + 'box-direction'];
  72. } else {
  73. return _Declaration.prototype.old.call(this, prop, prefix);
  74. }
  75. };
  76. return FlexDirection;
  77. }(Declaration);
  78. Object.defineProperty(FlexDirection, 'names', {
  79. enumerable: true,
  80. writable: true,
  81. value: ['flex-direction', 'box-direction', 'box-orient']
  82. });
  83. module.exports = FlexDirection;