flex-direction.js 4.0 KB

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