flex.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 list = require('postcss').list;
  6. var flexSpec = require('./flex-spec');
  7. var Declaration = require('../declaration');
  8. var Flex = /*#__PURE__*/function (_Declaration) {
  9. _inheritsLoose(Flex, _Declaration);
  10. function Flex() {
  11. return _Declaration.apply(this, arguments) || this;
  12. }
  13. var _proto = Flex.prototype;
  14. /**
  15. * Change property name for 2009 spec
  16. */
  17. _proto.prefixed = function prefixed(prop, prefix) {
  18. var spec;
  19. var _flexSpec = flexSpec(prefix);
  20. spec = _flexSpec[0];
  21. prefix = _flexSpec[1];
  22. if (spec === 2009) {
  23. return prefix + 'box-flex';
  24. }
  25. return _Declaration.prototype.prefixed.call(this, prop, prefix);
  26. }
  27. /**
  28. * Return property name by final spec
  29. */
  30. ;
  31. _proto.normalize = function normalize() {
  32. return 'flex';
  33. }
  34. /**
  35. * Spec 2009 supports only first argument
  36. * Spec 2012 disallows unitless basis
  37. */
  38. ;
  39. _proto.set = function set(decl, prefix) {
  40. var spec = flexSpec(prefix)[0];
  41. if (spec === 2009) {
  42. decl.value = list.space(decl.value)[0];
  43. decl.value = Flex.oldValues[decl.value] || decl.value;
  44. return _Declaration.prototype.set.call(this, decl, prefix);
  45. }
  46. if (spec === 2012) {
  47. var components = list.space(decl.value);
  48. if (components.length === 3 && components[2] === '0') {
  49. decl.value = components.slice(0, 2).concat('0px').join(' ');
  50. }
  51. }
  52. return _Declaration.prototype.set.call(this, decl, prefix);
  53. };
  54. return Flex;
  55. }(Declaration);
  56. _defineProperty(Flex, "names", ['flex', 'box-flex']);
  57. _defineProperty(Flex, "oldValues", {
  58. auto: '1',
  59. none: '0'
  60. });
  61. module.exports = Flex;