flex-flow.js 3.4 KB

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