flex-direction.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Declaration = require('../declaration');
  7. var FlexDirection = /*#__PURE__*/function (_Declaration) {
  8. _inheritsLoose(FlexDirection, _Declaration);
  9. function FlexDirection() {
  10. return _Declaration.apply(this, arguments) || this;
  11. }
  12. var _proto = FlexDirection.prototype;
  13. /**
  14. * Return property name by final spec
  15. */
  16. _proto.normalize = function normalize() {
  17. return 'flex-direction';
  18. }
  19. /**
  20. * Use two properties for 2009 spec
  21. */
  22. ;
  23. _proto.insert = function insert(decl, prefix, prefixes) {
  24. var spec;
  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. }
  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, dir;
  39. if (v === 'inherit' || v === 'initial' || v === 'unset') {
  40. orient = v;
  41. dir = v;
  42. } else {
  43. orient = v.includes('row') ? 'horizontal' : 'vertical';
  44. dir = v.includes('reverse') ? '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. * Clean two properties for 2009 spec
  63. */
  64. ;
  65. _proto.old = function old(prop, prefix) {
  66. var spec;
  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. _defineProperty(FlexDirection, "names", ['flex-direction', 'box-direction', 'box-orient']);
  79. module.exports = FlexDirection;