flex-flow.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = /*#__PURE__*/function (_Declaration) {
  8. _inheritsLoose(FlexFlow, _Declaration);
  9. function FlexFlow() {
  10. return _Declaration.apply(this, arguments) || this;
  11. }
  12. var _proto = FlexFlow.prototype;
  13. /**
  14. * Use two properties for 2009 spec
  15. */
  16. _proto.insert = function insert(decl, prefix, prefixes) {
  17. var spec;
  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. }
  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.includes('row') ? 'horizontal' : 'vertical';
  38. var dir = value.includes('reverse') ? '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. return FlexFlow;
  55. }(Declaration);
  56. _defineProperty(FlexFlow, "names", ['flex-flow', 'box-direction', 'box-orient']);
  57. module.exports = FlexFlow;