You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.0 KiB

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