flex-flow.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 FlexFlow = function (_Declaration) {
  8. _inherits(FlexFlow, _Declaration);
  9. function FlexFlow() {
  10. _classCallCheck(this, FlexFlow);
  11. return _possibleConstructorReturn(this, _Declaration.apply(this, arguments));
  12. }
  13. /**
  14. * Use two properties for 2009 spec
  15. */
  16. FlexFlow.prototype.insert = function insert(decl, prefix, prefixes) {
  17. var spec = void 0;
  18. var _flexSpec = flexSpec(prefix);
  19. spec = _flexSpec[0];
  20. prefix = _flexSpec[1];
  21. if (spec !== 2009) {
  22. return _Declaration.prototype.insert.call(this, decl, prefix, prefixes);
  23. } else {
  24. var values = decl.value.split(/\s+/).filter(function (i) {
  25. return i !== 'wrap' && i !== 'nowrap' && 'wrap-reverse';
  26. });
  27. if (values.length === 0) {
  28. return undefined;
  29. }
  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 value = values[0];
  37. var orient = value.indexOf('row') !== -1 ? 'horizontal' : 'vertical';
  38. var dir = value.indexOf('reverse') !== -1 ? 'reverse' : 'normal';
  39. var cloned = this.clone(decl);
  40. cloned.prop = prefix + 'box-orient';
  41. cloned.value = orient;
  42. if (this.needCascade(decl)) {
  43. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  44. }
  45. decl.parent.insertBefore(decl, cloned);
  46. cloned = this.clone(decl);
  47. cloned.prop = prefix + 'box-direction';
  48. cloned.value = dir;
  49. if (this.needCascade(decl)) {
  50. cloned.raws.before = this.calcBefore(prefixes, decl, prefix);
  51. }
  52. return decl.parent.insertBefore(decl, cloned);
  53. }
  54. };
  55. return FlexFlow;
  56. }(Declaration);
  57. Object.defineProperty(FlexFlow, 'names', {
  58. enumerable: true,
  59. writable: true,
  60. value: ['flex-flow', 'box-direction', 'box-orient']
  61. });
  62. module.exports = FlexFlow;