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